c - Under what circumstances (if ever) does strcat() hang? -


i have code in function in c:

char* root = "/home/os/homework/user/honorsupgrade/html"; requestinfo->resource = "/bing" printf("1\n"); int counter = 0; for(counter = 0; counter < 100; counter++) {     if(root[counter] == '\0')     {         printf("true1\n");         break;     } } for(counter = 0; counter < 100; counter++) {     if(requestinfo->resource[counter] == '\0')     {         printf("true2\n");         break;     } } printf("2\n"); fflush(stdout); strcat(root, requestinfo->resource); printf("3\n"); fflush(stdout); return open(root, 0_rdonly); 

...

request info's stuff, needed

struct reqinfo {     char *resource; } 

i have created 2 string (character pointers) in c, reason when pass these methods strcat(), strcat() never returns. causes program hang. have tested ensure both strings have null terminators (so strcat isn't trying concatenate more should). program print 1 , 2, never print 3, meaning never gets past strcat() call, flushing buffer make sure there isn't problem there. \

edit: i've created struct outside of block of code, i'm getting same issues when replacing "requestinfo->resource" char* resource , making "/bing"

attempting write const char *

even though char* root char *, points const char *. , writing undefined behavior.

char* root = "/home/os/homework/user/honorsupgrade/html"; .... strcat(root, requestinfo->resource); 

code should allocate right sized working buffer instead.

char buffer[1000]; strcpy(buffer, root); strcat(buffer, requestinfo->resource); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -