Issue information

Issue ID
#5232
Status
Fixed
Severity
Low
Started
Hercules Elf Bot
Jan 11, 2012 22:11
Last Post
Hercules Elf Bot
Apr 19, 2012 15:35
Confirmation
N/A

Hercules Elf Bot - Jan 11, 2012 22:11

Originally posted by [b]Lighta[/b]
Ok so just a little warning but I'm not quite found of those and I really dun like much this one.
This may be good or wrong depending on your compiler but is just like doing :
i = i++ + ++i + ++i;

So enought blabla just a little patch to correct this :
[codebox]
Index: src/map/script.c
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -12726,12 +12726,14 @@
{
const char *str = script_getstr(st,2);
char *output;
- int i = 0;
+ int i = 0, j=0;

output = (char*)aMallocA(strlen(str) + 1);

- while(str[i] != '\0')
- output[i++] = TOUPPER(str[i]);
+ while(str[i] != '\0'){
+ j=i++;
+ output[j] = TOUPPER(str[i]);
+ }
output[i] = '\0';

script_pushstr(st, output);
@@ -12745,12 +12747,14 @@
{
const char *str = script_getstr(st,2);
char *output;
- int i = 0;
+ int i = 0, j=0;

output = (char*)aMallocA(strlen(str) + 1);

- while(str[i] != '\0')
- output[i++] = TOLOWER(str[i]);
+ while(str[i] != '\0'){
+ j=i++;
+ output[j] = TOLOWER(str[i]);
+ }
output[i] = '\0';

script_pushstr(st, output);
[/codebox]

Hercules Elf Bot - Jan 11, 2012 22:14

Originally posted by [b]Ind[/b]
whats your compiler?

Hercules Elf Bot - Jan 11, 2012 22:34

Originally posted by [b]Gepard[/b]
It is explained in N1124


[quote]
Between the previous and next sequence point an object shall have its stored value
modified at most once by the evaluation of an expression. Furthermore, the prior value
shall be read only to determine the value to be stored.
(...)


This paragraph renders undefined statement expressions such as[CODE]
i = ++i + 1;
a[i++] = i;[/CODE]
while allowing[CODE]
i = i + 1;
a[i] = i;[/CODE][/quote]

Hercules Elf Bot - Jan 12, 2012 1:37

Originally posted by [b]Lighta[/b]
gcc with netbeans IDE Ind, those fonction still work fine for me, but I found it bad to keep undefined behaviour when it's so easy to fix.

Hercules Elf Bot - Jan 12, 2012 2:11

Originally posted by [b]Ind[/b]
which version of gcc? I use 4.3 and don't have these errors oo

Hercules Elf Bot - Jan 12, 2012 2:59

Originally posted by [b]Lighta[/b]
Maybe our configure option ain't the same. Here my gcc version:
[quote]
~/Myscript/RO/Servs/rathena/trunk$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6.1/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
[/quote]

Here the error in compilation. (I could get it with 2> too, but just so you can see with compile flag option)
[quote]
/usr/bin/gcc -g3 -gdwarf-2 -pipe -ffast-math -Wall -Wno-sign-compare -Wno-unused-parameter -Wno-pointer-sign -Wno-switch -fno-strict-aliasing -DHAVE_SETRLIMIT -DHAVE_STRNLEN -Wno-unused -Wno-parentheses -DHAVE_MONOTONIC_CLOCK -I../../3rdparty/mt19937ar -DPCRE_SUPPORT -I/usr/include/mysql -I../common -I/usr/include -c -o obj_sql/script.o script.c
script.c: In function ‘buildin_strtoupper’:
script.c:12734:11: warning: operation on ‘i’ may be undefined [-Wsequence-point]
script.c: In function ‘buildin_strtolower’:
script.c:12753:11: warning: operation on ‘i’ may be undefined [-Wsequence-point]
[/quote]

Hercules Elf Bot - Jan 12, 2012 3:32

Originally posted by [b]Ind[/b]
should be fixed in [rev=15435]