[Bug 6000] New: scanf format "%i" does not recognise octal nor hexadecimal numbers

Wine Bugs wine-bugs at winehq.org
Sat Aug 19 12:21:11 CDT 2006


http://bugs.winehq.org/show_bug.cgi?id=6000

           Summary: scanf format "%i" does not recognise octal nor
                    hexadecimal numbers
           Product: Wine
           Version: CVS
          Platform: Other
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: wine-binary
        AssignedTo: wine-bugs at winehq.org
        ReportedBy: popej at friko.onet.pl


For format "%i" scanf does not recognise octal and hexadecimal prefikses. This is example of application code, that will not work correctly under wine:

char data[] = "17 017 0x17";
int a, b, c;
sscanf(data, "%i%i%i", &a, &b, &c);


IMHO error is in /wine/dlls/msvcrt/scanf.h . This is current version from CVS:

171             case 'i': /* generic integer */
172                 base = 10;
173             number: {
174                     /* read an integer */
175                     ULONGLONG cur = 0;
176                     int negative = 0;
177                     int seendigit=0;
178                     /* skip initial whitespace */
179                     while ((nch!=_EOF_) && _ISSPACE_(nch))
180                         nch = _GETC_(file);
181                     /* get sign */
182                     if (nch == '-' || nch == '+') {
183                         negative = (nch=='-');
184                         nch = _GETC_(file);
185                         if (width>0) width--;
186                     }
187                     /* look for leading indication of base */
188                     if (width!=0 && nch == '0') {
189                         nch = _GETC_(file);
190                         if (width>0) width--;
191                         seendigit=1;
192                         if (width!=0 && (nch=='x' || nch=='X')) {
193                             if (base==0)
194                                 base=16;
195                             if (base==16) {
196                                 nch = _GETC_(file);
197                                 if (width>0) width--;
198                                 seendigit=0;
199                             }
200                         } else if (base==0)
201                             base = 8;
202                     }
 
Should be:

171             case 'i': /* generic integer */
172                 base = 0;  /* proposed correction - base unknown */
...
188                     if (width!=0 && nch == '0') {
...
202                     }
/* proposed correction - insert after line 202: */
                        if (base == 0)  /* when there is no prefix */
                            base = 10;  /* set default base */

-- 
Configure bugmail: http://bugs.winehq.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the wine-bugs mailing list