subtype,
@subtype@insufferable.tools avatar

This day’s frustrating debugging session sponsored by shitty error handling in <stdlib.h>, namely that atoi(garbage) == 0 and so it’s not straightforward to tell if the 0 was there or not :cirno_for_reals:

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype but yeah i love these functions where error return is also a possible valid return

subtype,
@subtype@insufferable.tools avatar

@Ukko
>use strtol

https://en.cppreference.com/w/c/string/byte/strtol

>if no conversion can be performed, ​0​ is returned.

how does that help me

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype it sets endptr so you can see how much it has parsed / whether it has parsed anything at all

subtype,
@subtype@insufferable.tools avatar

@Ukko ah right, thanks!

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype you're welcome, C standard library is amazing

paula9,
@paula9@comp.lain.la avatar

@Ukko @subtype doesn't it also set errno

subtype,
@subtype@insufferable.tools avatar

@paula9 @Ukko https://busybox.net/~landley/c99-draft.html#7.20.1

>The functions atof, atoi, atol, and atoll need not affect the value of the integer expression errno on an error. If the value of the result cannot be represented, the behavior is undefined.

so it's actually worse than I thought lmao

paula9,
@paula9@comp.lain.la avatar

@subtype @Ukko just verify the input yourself :meowNerd:

Ukko,
@Ukko@akko.disqordia.space avatar

@paula9 @subtype just write your own alternative C core library

paula9,
@paula9@comp.lain.la avatar

@Ukko @subtype there are actual alternative c core libraries
facebook has one for c++, don't know about c

Ukko,
@Ukko@akko.disqordia.space avatar

@paula9 @subtype the implementation MAY also set errno to EINVAL in case no conversion was performed

Ukko,
@Ukko@akko.disqordia.space avatar

@paula9 @subtype (that's for strto{l,ll}, atoi does nothing)

Ukko,
@Ukko@akko.disqordia.space avatar

@subtype use strtol

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • Hentai
  • doujinshi
  • announcements
  • general
  • All magazines