Timeline for Taking arbitrary length input in C
Current License: CC BY-SA 3.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 17, 2016 at 4:48 | vote | accept | galois | ||
Jul 25, 2016 at 16:10 | comment | added | Adam Martin | Neither answer has addressed this concern yet, but in C it is perfectly fine to leave it up to the calling function to free the returned pointer. However, having size in the calling signature would make me as a user think that is the maximum number of bytes read, as opposed to the initial buffer size, since you shrink the buffer to len in your return. | |
Jul 25, 2016 at 15:20 | answer | added | chux | timeline score: 9 | |
Jul 25, 2016 at 10:30 | comment | added | Daniel Jour |
realloc does not free the pointer that was passed to it in case of failure. Thus you have two possible memory leaks there.
|
|
Jul 25, 2016 at 6:11 | history | tweeted | twitter.com/StackCodeReview/status/757458305631518720 | ||
Jul 25, 2016 at 5:47 | history | edited | galois | CC BY-SA 3.0 |
added 6 characters in body
|
Jul 25, 2016 at 5:47 | comment | added | galois |
Yep - I had changed str to input_str before I brought the code over. thanks.
|
|
Jul 25, 2016 at 5:00 | answer | added | mleyfman | timeline score: 21 | |
Jul 25, 2016 at 4:59 | comment | added | JS1 |
This line seems wrong: input_str = realloc(str, size += 16); because str is undefined. Did you copy and paste incorrectly?
|
|
Jul 25, 2016 at 3:01 | history | asked | galois | CC BY-SA 3.0 |