Issue 173103
Summary "0x." is considered a valid hex floating-point number to sscanf()
Labels new issue
Assignees
Reporter tydeman
    The following program:

#include <assert.h>
#include <limits.h>
#include <errno.h>
#include <stdio.h>
#include <float.h>
#include <fenv.h>
#include <complex.h>
#include <math.h>

#pragma STDC FENV_ACCESS ON
#pragma STDC FP_CONTRACT OFF
#pragma STDC FENV_ROUND FE_TONEAREST
#pragma STDC FENV_DEC_ROUND FE_DEC_TONEAREST
#pragma STDC CX_LIMITED_RANGE OFF

int main(void){
  if(1){
    double d35 = -1.;
    int i35 = -1;
    int count = -1;
    char string[8] = "1234567";
    i35 = sscanf("junk()", "%le%n%8s", &d35, &count, string );
    (void)printf("Results for known junk\n");
    (void)printf("i35=%i\n", i35);
 (void)printf("d35=%g\n", d35);
    (void)printf("count=%i\n", count);
    (void)printf("string='%s'\n", string);

 (void)printf("\nBad results for bad hex floating point\n");
    i35 = sscanf("0x.p0()", "%le%n%8s", &d35, &count, string );
 (void)printf("i35=%i\n", i35);
    (void)printf("d35=%g\n", d35);
 (void)printf("count=%i\n", count);
    (void)printf("string='%s'\n", string);
  }
 return 0;
}

Get:
Results for known junk
i35=0
d35=-1
count=-1
string='1234567'

Bad results for bad hex floating point
i35=2
d35=0
count=3
string='p0()'

"0x.p0" is missing hex digits on either side the the decimal point,
so is not a valid hex floating-point number, so is a matching failure.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to