Skip to main content
fix the its
Source Link
DinoCoderSaurus
  • 28.6k
  • 2
  • 12
  • 31

This declaration char* request = ""; basically makes request a const char*, and as such is immutable. You should not "set" it to "", rather it needs to have some memory allocated before anything is copied into it.

Similarly, this line requestHttpAndTail[i] = '\0'; fails because requeHttpAndTail is a pointer into line's memory, line is a const char* and thus immutable.

And beware, this abs_path = request; is a slippery slope. Assuming request is a locally allocated variable, it'sits memory will be destroyed when program control returns to main, leaving abs_path, well, not what you expect.

Notice how abs_path and query are declared in server. You would create a much closer repro case if p and q were declared similarly. (Besides the fact that as written, they are immutable).

This declaration char* request = ""; basically makes request a const char*, and as such is immutable. You should not "set" it to "", rather it needs to have some memory allocated before anything is copied into it.

Similarly, this line requestHttpAndTail[i] = '\0'; fails because requeHttpAndTail is a pointer into line's memory, line is a const char* and thus immutable.

And beware, this abs_path = request; is a slippery slope. Assuming request is a locally allocated variable, it's memory will be destroyed when program control returns to main, leaving abs_path, well, not what you expect.

Notice how abs_path and query are declared in server. You would create a much closer repro case if p and q were declared similarly. (Besides the fact that as written, they are immutable).

This declaration char* request = ""; basically makes request a const char*, and as such is immutable. You should not "set" it to "", rather it needs to have some memory allocated before anything is copied into it.

Similarly, this line requestHttpAndTail[i] = '\0'; fails because requeHttpAndTail is a pointer into line's memory, line is a const char* and thus immutable.

And beware, this abs_path = request; is a slippery slope. Assuming request is a locally allocated variable, its memory will be destroyed when program control returns to main, leaving abs_path, well, not what you expect.

Notice how abs_path and query are declared in server. You would create a much closer repro case if p and q were declared similarly. (Besides the fact that as written, they are immutable).

Source Link
DinoCoderSaurus
  • 28.6k
  • 2
  • 12
  • 31

This declaration char* request = ""; basically makes request a const char*, and as such is immutable. You should not "set" it to "", rather it needs to have some memory allocated before anything is copied into it.

Similarly, this line requestHttpAndTail[i] = '\0'; fails because requeHttpAndTail is a pointer into line's memory, line is a const char* and thus immutable.

And beware, this abs_path = request; is a slippery slope. Assuming request is a locally allocated variable, it's memory will be destroyed when program control returns to main, leaving abs_path, well, not what you expect.

Notice how abs_path and query are declared in server. You would create a much closer repro case if p and q were declared similarly. (Besides the fact that as written, they are immutable).