Fossil

Check-in [4a98d2aa]
Login

Check-in [4a98d2aa]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The th1-expr-3 test revealed that Th_SetResultInt() could produce incorrect result for INT_MIN. Ensure that -1*iVal is positive for all values and remove unsiged casts. Seems a common optimisation problem with gcc on various verisons from 10 through 13 on Linux, NetBSD and OmniOS on various architectures.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | th-int-min-errors
Files: files | file ages | folders
SHA3-256: 4a98d2aae1b6cc47ebd97886e6948d7c4374a7e24a11d24315b8e3de904a8bce
User & Date: preben 2023-12-03 21:36:12
Context
2024-01-04
09:32
Use an unsigned int in Th_SetResultInt() to address issues with GCC for INT_MIN. ... (check-in: 301edfc0 user: preben tags: trunk)
2023-12-03
21:36
The th1-expr-3 test revealed that Th_SetResultInt() could produce incorrect result for INT_MIN. Ensure that -1*iVal is positive for all values and remove unsiged casts. Seems a common optimisation problem with gcc on various verisons from 10 through 13 on Linux, NetBSD and OmniOS on various architectures. ... (Closed-Leaf check-in: 4a98d2aa user: preben tags: th-int-min-errors)
2023-12-01
22:37
Typo corrections in comments only. No change in functionality. ... (check-in: a8b6fdc8 user: andybradford tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th.c.

2868
2869
2870
2871
2872
2873
2874

2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892

/*
** Set the result of the interpreter to the th1 representation of
** the integer iVal and return TH_OK.
*/
int Th_SetResultInt(Th_Interp *interp, int iVal){
  int isNegative = 0;

  char zBuf[32];
  char *z = &zBuf[32];

  if( iVal<0 ){
    isNegative = 1;
    iVal = iVal * -1;
  }
  *(--z) = '\0';
  *(--z) = (char)(48+((unsigned)iVal%10));
  while( (iVal = ((unsigned)iVal/10))>0 ){
    *(--z) = (char)(48+((unsigned)iVal%10));
    assert(z>zBuf);
  }
  if( isNegative ){
    *(--z) = '-';
  }

  return Th_SetResult(interp, z, -1);







>





|


|
|
|







2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893

/*
** Set the result of the interpreter to the th1 representation of
** the integer iVal and return TH_OK.
*/
int Th_SetResultInt(Th_Interp *interp, int iVal){
  int isNegative = 0;
  unsigned int uVal = iVal;
  char zBuf[32];
  char *z = &zBuf[32];

  if( iVal<0 ){
    isNegative = 1;
    uVal = iVal * -1;
  }
  *(--z) = '\0';
  *(--z) = (char)(48+(uVal%10));
  while( (uVal = (uVal/10))>0 ){
    *(--z) = (char)(48+(uVal%10));
    assert(z>zBuf);
  }
  if( isNegative ){
    *(--z) = '-';
  }

  return Th_SetResult(interp, z, -1);