From: SourceForge.net <no...@so...> - 2008-12-19 16:50:46
|
Bugs item #2445962, was opened at 2008-12-18 19:22 Message generated for change (Comment added) made by keithmarshall You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=2445962&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: mingw runtime >Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Keishi Suenaga (skeishi) >Assigned to: Keith Marshall (keithmarshall) Summary: Mingw getopt reset bug. Initial Comment: Following code returns no response, with mingwrt-3.15.1-mingw32.tar.gz. Remove optind=0; line then it works fine ( returns "opt=U" ). Keishi Suenaga(sk...@ya...) ------------------------------------------------- #include <stdio.h> #include <getopt.h> int main(int argc, char **argv) { int opt; int c = 2; char *v[2] = { "opt", "-U" }; optind = 0; /* this is the line */ opt = getopt(c, v, "Uv"); printf("opt=%c \n", opt ); return 0; } ------------------------------------------------- If you need fllowing Infomation. Host Operating System Information and Version Microsoft Windows XP Professional x64 Edition Version 2003 Service Pack 2 GCC Version Using built-in specs. Target: mingw32 Configured with: ../gcc-4.3.0/configure --enable-languages=c,ada,c++,fortran,jav a,objc,obj-c++ --disable-sjlj-exceptions --enable-shared --enable-libgcj --enabl e-libgomp --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enab le-concept-checks --enable-version-specific-runtime-libs --build=mingw32 --with- bugurl=http://www.mingw.org/bugs.shtml --prefix=/mingw --with-gmp=/mingw/src/gcc /gmp-mpfr-root --with-mpfr=/mingw/src/gcc/gmp-mpfr-root --with-libiconv-prefix=/ mingw/src/gcc/libiconv-root Thread model: win32 gcc version 4.3.0 20080305 (alpha-testing) mingw-20080502 (GCC) Binutils Version GNU ld (GNU Binutils) 2.18.50.20080109 Build Environment uname -a MINGW32_NT-5.2 MEDAKA 1.0.11(0.46/3/2) 2008-08-25 23:40 i686 Msys ---------------------------------------------------------------------- >Comment By: Keith Marshall (keithmarshall) Date: 2008-12-19 16:50 Message: Thanks for the report. Your patch confirms that my own evaluation of the problem is correct. I introduced a potential infinite recursion, when I fixed bug 2144266; using `optbase' instead of `optind' for internal state fixed that, but overlooked the need to update `optind', to break an internal recursive call cycle, if the user sets `optind' to less than 1. Unfortunately, while your patch appears to break the cycle, my own analysis tells me it isn't sufficient to fix it completely -- in your test case, the `optind' reset action occurs in the second pass, rather than where it belongs, in the first; however, I do have my own alternative patch almost ready to commit. ---------------------------------------------------------------------- Comment By: Keishi Suenaga (skeishi) Date: 2008-12-19 01:12 Message: I made a patch. This works fine in my case. Keishi Suenaga(sk...@ya...) ------------------------------------------------------------------------- diff -c mingwrt-3.15.1-mingw32/mingwex/getopt.c.orig mingwrt-3.15.1-mingw32/mingwex/getopt.c *** mingwrt-3.15.1-mingw32/mingwex/getopt.c.orig Sun Oct 5 03:12:01 2008 --- mingwrt-3.15.1-mingw32/mingwex/getopt.c Fri Dec 19 09:47:02 2008 *************** *** 326,331 **** --- 326,332 ---- * adjusted `optind' value, (but never to less than zero). */ optmark = optbase = argind = (optind > 0) ? optind - 1 : 0; + if(optind <= 0) optind = 1; nextchar = NULL; } --------------------------------------------------------------------------- ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=2445962&group_id=2435 |