public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/13609] New: sscanf optimization error
@ 2004-01-07 22:02 BStrauss-gcc at feliscatus dot org
2004-01-07 22:25 ` [Bug optimization/13609] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: BStrauss-gcc at feliscatus dot org @ 2004-01-07 22:02 UTC (permalink / raw)
To: gcc-bugs
Different results for small test program when compiled -O2 vs no optimization
(non-optimized version is right):
#define cNV2N(a, b) printf("-> %10u expected %10u\n",
convertNtopVersionToNumber(a), b)
unsigned int convertNtopVersionToNumber(char *versionString) {
/* This one is purely an arbitrary conversion.
*
* But it knows about the version # schemes we've used in the past
* e.g. 2.2c, 2.2.50, 2.2.97, 3.0pre1, 3.0rc1 etc. so that the number truly
is relative
* for numeric testing.
*
* The goal is to get the following converted to ascending numeric order:
*
* 1.3 2.1 2.1.2 2.1.3 2.1.50 2.1.90 2.2 2.2a 2.2b 2.2c 2.2.50 2.2.97
3.0pre1 3.0rc1 3.0
*
* e.g.:
*
* 1.3 103000000
* 2.1 201000000
* 2.1.1 201000001
* 2.1.2 201000002
* 2.1.3 201000003
* 2.1.50 201050000
* 2.1.90 201090000
* 2.2 202000000
* 2.2a 202000100
* 2.2b 202000200
* 2.2c 202000300
* 2.2.50 202050000
* 2.2.90 202090000
* 3.0pre1 299998001
* 3.0rc1 299999001
* 3.0rc2 299999002
* 3.0 300000000
*
* n.m -> nmm000000
* n.m.x -> nmmyyy0xx (if x>=50 yyy=x else xx=x)
* n.ml -> nmm000l00 (where a=1, b=2, etc.)
*/
unsigned int f, n=0, m=0, x=0, y=0, c=0, prerc=0;
unsigned char l=0;
if (versionString == 0) {
return 999999999;
}
printf("'%10s'", versionString);
f = sscanf(versionString, "%u.%upre%u", &n, &m, &x);
if(f>=3) {
prerc=2;
} else {
f = sscanf(versionString, "%u.%urc%u", &n, &m, &x);
if(f>=3) {
prerc=1;
} else {
f = sscanf(versionString, "%u.%u%[a-z].%u", &n, &m, &l, &x);
if(f>=3) {
if(l>0)
l = tolower(l) - 'a' + 1;
} else {
l = 0;
f = sscanf(versionString, "%u.%u.%u", &n, &m, &x);
if (f<=0) {
return 999999999;
}
}
}
}
if (x>=50) {
y=x;
x=0;
}
printf("\tis n%u m%u y%u l%u x%u prerc%u f=%u\t", n, m, y, l, x, prerc, f);
return n*100000000 + m*1000000 + y*1000 + l*100 + x - 1000*prerc;
}
int main(int argc, char *argv[]) {
cNV2N("2.2", 202000000);
cNV2N("2.2c", 202000300);
cNV2N("2.2c.1", 202000301);
}
$ gcc sscanftest.c -o sscanftest
$ ./sscanftest
' 2.2' is n2 m2 y0 l0 x0 prerc0 f=2 -> 202000000 expected
202000000
' 2.2c' is n2 m2 y0 l3 x0 prerc0 f=3 -> 202000300 expected
202000300
' 2.2c.1' is n2 m2 y0 l3 x1 prerc0 f=4 -> 202000301 expected
202000301
$ gcc -O2 sscanftest.c -o sscanftest
$ ./sscanftest
' 2.2' is n2 m2 y0 l0 x0 prerc0 f=2 -> 202000000 expected
202000000
' 2.2c' is n0 m2 y0 l3 x0 prerc0 f=3 -> 2000300 expected
202000300
' 2.2c.1' is n0 m2 y0 l3 x1 prerc0 f=4 -> 2000301 expected
202000301
$ gcc --version
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
--
Summary: sscanf optimization error
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: BStrauss-gcc at feliscatus dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13609
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug optimization/13609] sscanf optimization error
2004-01-07 22:02 [Bug optimization/13609] New: sscanf optimization error BStrauss-gcc at feliscatus dot org
@ 2004-01-07 22:25 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-07 22:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-01-07 22:25 -------
Not a bug %[a-z] expects a char array and you are only supplying it with enough room for zero
characters.
>From the man of printf:
[ Matches a nonempty sequence of characters from the specified set of accepted
characters; the next pointer must be a pointer
to char, and there must be enough room for all the characters in the string, plus a
terminating NUL character. The usual
skip of leading white space is suppressed. The string is to be made up of characters in
(or not in) a particular set; the
set is defined by the characters between the open bracket [ character and a close
bracket ] character. The set excludes
those characters if the first character after the open bracket is a circumflex ^. To include
a close bracket in the set,
make it the first character after the open bracket or the circumflex; any other position
will end the set. The hyphen char-
acter - is also special; when placed between two other characters, it adds all intervening
characters to the set. To include
a hyphen, make it the last character before the final close bracket. For instance,
`[^]0-9-]' means the set `everything
except close bracket, zero through nine, and hyphen'. The string ends with the
appearance of a character not in the (or,
with a circumflex, in) set or when the field width runs out.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13609
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-01-07 22:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-07 22:02 [Bug optimization/13609] New: sscanf optimization error BStrauss-gcc at feliscatus dot org
2004-01-07 22:25 ` [Bug optimization/13609] " pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).