Welcome to the Builder Academy

Question Trouble with Strchr

More
16 Apr 2018 15:39 #7939 by Chime
Trouble with Strchr was created by Chime
Getting some weird data corruptiony-type stuff sometimes when my RPOSE command is used.

colorPose is intended to identify when a quotation mark is added to a string, then color what's between them.

The culpable function:
Code:
char * colorPose(char *argument) { char *final_string; char tempString[MAX_STRING_LENGTH]; bool inquotes = FALSE; int offset = 0; int x = 0; while (x < strlen(argument)) { if (argument[x] == '"') { if (inquotes == TRUE) { tempString[x + offset] = '@'; tempString[x + offset + 1] = 'n'; tempString[x + offset + 2] = '"'; offset += 2; inquotes = FALSE; } else { tempString[x + offset] = '"'; tempString[x + offset + 1] = '@'; tempString[x + offset + 2] = 'W'; offset += 2; inquotes = TRUE; } } else tempString[x + offset] = argument[x]; x++; } if (inquotes == TRUE) { tempString[x + offset] = '"'; tempString[x + offset + 1] = '@'; tempString[x + offset + 2] = 'n'; offset += 3; inquotes = FALSE; } if (CONFIG_SPECIAL_IN_COMM && legal_communication(tempString)) parse_at(tempString); tempString[x + offset] = '\0'; final_string = tempString; return final_string; }

Called in do_rpose (Maybe this is the problem portion, instead of the function itself?):
Code:
if (strchr(argument, '"') != NULL) argument = colorPose(argument);

Testing shows this, for example of the weird:

rpecho Chime shrieks, "Why though?"
--> Chime shrieks, "Why though?"H~ssad


I think it's time to acknowledge I'm nowhere near clever enough, a few hours of bashing at the function considered, to detect what the trouble is without a more educated eye.

Is there an issue I'm missing?

Please Log in or Create an account to join the conversation.

More
16 Apr 2018 22:24 #7941 by thomas
Replied by thomas on topic Trouble with Strchr
Move this line above the call to parse_at:
Code:
tempString[x + offset] = '\0';
The following user(s) said Thank You: Chime

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 04:26 #7942 by Chime
Replied by Chime on topic Trouble with Strchr
Thank you, Thomas. That resolved it!

Please Log in or Create an account to join the conversation.

Time to create page: 0.219 seconds