Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 18 Dec 2022 11:06:14 +0100
From: Quentin Rameau <>
Subject: Re: Bug in atoll strtoll, the output of then differ

> Hello !


> Doing some work with emscripten with this project 
> I was getting some 
> errors with the usage of "atoll" and with this small program to compare 
> the output of "musl" and "glibc" I found what seems to be a bug in 
> "atoll" because with "musl" it gives a different output than "strtoll".
> =====
> #include <stdio.h>
> #include <stdlib.h>
> int main(int argc, char *argv[])
> {
>      const char *s = "9223372036854775808";
>      long  long ll = atoll(s);
>      long long ll2 = strtoll (s, (char **) NULL, 10);
>      int imax = 0x7fffffff;
>      printf("%s : %lld : %lld : %d : %d\n",  s, ll, ll2, imax, ll <= imax);
>      return 0;
> }

This is not a bug in musl, but a bug in the code,
9223372036854775808 is outside the range of long long,
so the behavior is undefined.

As recommended by the standard, ato* should only be used if the input
is known to always be in the target range,
otherwise use the strto* functins and do proper error handling.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.