Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 13 Jun 2017 07:53:54 -0700
From: Khem Raj <raj.khem@...il.com>
To: musl@...ts.openwall.com
Subject: Re: Different behavior (strtod) between musl and glibc

On Tue, Jun 13, 2017 at 7:43 AM, Xiaowei Zhan <zhanxw@...il.com> wrote:
> Hello,
>
> I notice that when pass a non-numeric char to strtod, musl will set errno to
> non-zero, but glibc will set errno to zero.

Musl is detecting that it can not perform the conversion due to invalid input.
It seems that musl is conforming to posix definition here
http://pubs.opengroup.org/onlinepubs/009695399/functions/strtod.html

> I am curious why this difference exists, and whether it is necessary to make
> strtod in musl behave similarly to glibc.
>
> Here is the toy program:
>
>
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char** argv) {
>   errno = 0;
>   char input[] = "NA023";
>   strtod(input, NULL);
>   printf("errno = %d\n", errno);
>   perror("strtod");
>
>   return 0;
> }
>
> Output (musl):
>
> bash-4.3# ./main
> errno = 22
> strtod: Invalid argument
>
> Output (glibc, Ubuntu 16.04):
>> ./main
> errno = 0
> strtod: Success
>
>
>
> Best,
> Xiaowei
>
>

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.