Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Tue, 13 Jun 2017 09:43:42 -0500
From: Xiaowei Zhan <zhanxw@...il.com>
To: musl@...ts.openwall.com
Subject: Different behavior (strtod) between musl and glibc

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.
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

Content of type "text/html" skipped

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.