Bug 424044

Summary: long double issue: isinf(strtold("+inf", NULL)) != 1
Product: [Developer tools] valgrind Reporter: Oran Agra <oran>
Component: memcheckAssignee: Julian Seward <jseward>
Status: RESOLVED DUPLICATE    
Severity: normal CC: bruno, pjfloyd
Priority: NOR    
Version: 3.18.1   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In:

Description Oran Agra 2020-07-09 21:48:15 UTC
SUMMARY
strtold("+inf",NULL) seems to return a non-inf value.

STEPS TO REPRODUCE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[])
{
    long double x = strtold("+inf", NULL);
    fprintf(stderr, "x = %Lf, isinf = %d\n", x, isinf(x));
    return 0;
}

OBSERVED RESULT
$ ./a.out
x = inf, isinf = 1
$ valgrind ./a.out
==2890624== Memcheck, a memory error detector
==2890624== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2890624== Using Valgrind-3.16.0 and LibVEX; rerun with -h for copyright info
==2890624== Command: ./a.out
==2890624== 
x = 11897314953572...., isinf = 0

EXPECTED RESULT
x = inf, isinf = 1

SOFTWARE/OS VERSIONS
Ubuntu 20.04
Linux ip-172-31-20-147 5.4.0-1015-aws #15-Ubuntu SMP Thu Jun 4 22:47:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
valgrind-3.16.0

ADDITIONAL INFORMATION
it seems to depend on the hardware (i didn't collect enough evidence), i noticed it happens on Xeon, but not on core i7-7700k (both using self built valgrind-3.16.0 on Ubuntu).

Seen it on both bare metal Xeon (Valgrind-3.15.0) and AWS c5.xlarge VM (Valgrind-3.16.0), also both with Ubuntu:
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz
stepping        : 7
microcode       : 0x5002f00
Comment 1 Bruno Haible 2023-03-17 20:42:36 UTC
The problem is with the isinf call. In this test case
====================================================
#include <math.h>
#include <stdio.h>

long double x;

int main ()
{
  x = 1.0L / 0.0L;
  printf ("%d %La %d\n", !!isinf (x), x, 33);
  return 0;
}
====================================================
we have two isinf calls:
1) in main,
2) inside glibc's fprintf routines, more exactly in glibc/stdio-common/printf_fphex.c, macro PRINTF_FPHEX_FETCH, line 109.

Both return 1 when run natively, but 0 when run under valgrind.
$ ./a.out
1 inf 33
$ valgrind ./a.out
0 0x8p+16381 33

Valgrind version: 3.18.1
Architecture: x86_64
OS: Linux 5.15.0 (Ubuntu 22.04)
GCC: 11.3
CPU: AMD Ryzen 7 4800U
Comment 2 Paul Floyd 2023-07-02 08:32:53 UTC

*** This bug has been marked as a duplicate of bug 421262 ***