News for hackers. Stuff that matters.
Re:Programming Idioms by WJW on Sunday August 15, 2021 @03:39PM (#28191810)
The longer I look at this example, the more weirdness I spot:

- There are no standard integer types that take 15 (decimal) digits to represent.

- The array contains ints instead of chars

- Why would you use fgets() instead of just gets()? (Though I don't touch C very often so perhaps that is considered proper style)

- Obviously no conversion of the digits into else, let alone specifying a base or handling a `0x` prefix for hexadecimal or a minus sign for negative numbers.

Re:Programming Idioms by jhgb on Sunday August 15, 2021 @04:29PM (#28192231)
> Why would you use fgets() instead of just gets()?

I assume it's because gets() ranks as "-10: It's impossible to get right" on Rusty's API Design Manifesto? (http://sweng.the-davies.net/Home/rustys-api-design-manifesto)

Re:Programming Idioms by WJW on Sunday August 15, 2021 @04:54PM (#28192455)
TIL. I have been leading a sheltered life in languages with garbage collectors that obscured the true horror of gets() from me.
Re:Programming Idioms by Someone on Sunday August 15, 2021 @06:52PM (#28193311)
> There are no standard integer types that take 15 (decimal) digits to represent

Nitpick: that is irrelevant. The code reads in at most 14 characters.

> Why would you use fgets() instead of just gets()?

You don’t use gets because it doesn’t exist anymore. It got removed in C11 (it rightfully was deemed so bad that backwards compatibility was sacrificed). You can use

  char *gets_s( char *str, rsize_t n )
, though.

(https://en.cppreference.com/w/c/io/gets)

Re:Programming Idioms by leetcrew on Sunday August 15, 2021 @03:43PM (#28191848)
gets is inherently unsafe unless the input is guaranteed (externally) to never overflow the buffer.
Re:Programming Idioms by mpweiher on Sunday August 15, 2021 @04:44PM (#28192360)

   man gets

   ...
   
   SECURITY CONSIDERATIONS
     The gets() function cannot be used securely.  Because of its lack of
     bounds checking, and the inability for the calling program to reliably
     determine the length of the next incoming line, the use of this function
     enables malicious users to arbitrarily change a running program's func-
     tionality through a buffer overflow attack.  It is strongly suggested
     that the fgets() function be used in all cases.  (See the FSA.)