Skip to main content
Code Review

Return to Question

Notice removed Draw attention by Community Bot
Bounty Ended with Toby Speight's answer chosen by Community Bot
edited tags
Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
Tweeted twitter.com/StackCodeReview/status/967066501378461696
Notice added Draw attention by chux
Bounty Started worth 100 reputation by chux
added 42 characters in body
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96
  1. When the buffer is insufficient, the rest of the line is consumed (and lost). An error is indicated.

  2. In C, a line of input is up to and including the '\n' C11 7.21.2 2. When the streams ends with something other than a new-line, how that is handled is implementation defined behavior. J.3.12. This code treats a '\n' and end-of-file as the same. In both cases, a '\n' is not include in the saved buffer.

  3. Allocating memory per external input can lead to abuse. This allows external forces to overwhelm memory allocation. The following does not use memory allocation like getline substitute that will enforce 'n' as limit of characters read or getline . Another alternative could use limited allocation, but that is not done here.

  4. If code reads a '0円', that is not practical to discern with fgets(). This code returns the size of the spacedspace used in dest, which includes an appended null character.

  5. Lesser issues include fgets() handling of NULL augments, small buffer size, undefined buffer state on ferror() and use of int vs size_t. The below code also clearly - I hope - handles that.

  6. An alternative allocate memory: Allocating memory per external input can lead to abuse. This allows external forces to overwhelm memory allocation. The following does not use memory allocation like getline substitute that will enforce 'n' as limit of characters read or getline . Another alternative could use limited allocation, but that is not done here.

Portability concerns: Might a common or rare case fail on some select systemsystems?

General comments. (on any code).

The code below is listed as one file for code review convenience, yet would usually would be is separatedseparate .ch, .hc files.

  1. When the buffer is insufficient, the rest of the line is consumed (and lost). An error is indicated.

  2. In C, a line of input is up to and including the '\n' C11 7.21.2 2. When the streams ends with something other than a new-line, how that is handled is implementation defined behavior. J.3.12. This code treats a '\n' and end-of-file as the same. In both cases, a '\n' is not include in the saved buffer.

  3. Allocating memory per external input can lead to abuse. This allows external forces to overwhelm memory allocation. The following does not use memory allocation like getline substitute that will enforce 'n' as limit of characters read or getline . Another alternative could use limited allocation, but that is not done here.

  4. If code reads a '0円', that is not practical to discern with fgets(). This code returns the size of the spaced used in dest, which includes an appended null character.

  5. Lesser issues include fgets() handling of NULL augments, small buffer size, undefined buffer state on ferror() and use of int vs size_t. The below code also clearly - I hope - handles that.

Portability concerns: Might a common or rare case fail on some select system?

General comments. (on any code)

The code below is listed as one for code review convenience, yet would usually be is separated .c, .h files.

  1. When the buffer is insufficient, the rest of the line is consumed (and lost). An error is indicated.

  2. In C, a line of input is up to and including the '\n' C11 7.21.2 2. When the streams ends with something other than a new-line, how that is handled is implementation defined behavior. J.3.12. This code treats a '\n' and end-of-file as the same. In both cases, a '\n' is not include in the saved buffer.

  3. If code reads a '0円', that is not practical to discern with fgets(). This code returns the size of the space used in dest, which includes an appended null character.

  4. Lesser issues include fgets() handling of NULL augments, small buffer size, undefined buffer state on ferror() and use of int vs size_t. The below code also clearly - I hope - handles that.

  5. An alternative allocate memory: Allocating memory per external input can lead to abuse. This allows external forces to overwhelm memory allocation. The following does not use memory allocation like getline substitute that will enforce 'n' as limit of characters read or getline . Another alternative could use limited allocation, but that is not done here.

Portability concerns: Might a common or rare case fail on some select systems?

General comments (on any code).

The code below is listed as one file for code review convenience, yet would usually would be is separate .h, .c files.

added 85 characters in body
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96

Performance concerns are appreciated when they are backed with real measurements.

Performance concerns are appreciated when they are backed with real measurements.

Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96
Loading
lang-c

AltStyle によって変換されたページ (->オリジナル) /