Should not be modifying the program's arguments. Problem raised by const
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 23 May 2009 02:36:03 +0000 (02:36 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 23 May 2009 02:36:03 +0000 (02:36 +0000)
correctness in gcc 4.4 and reported by Diego.

git-svn-id: http://svn.complang.org/ragel/trunk@872 052ea7fc-9027-0410-9066-f65837a77df0

ragel/main.cpp

index 1330cf8..5894c3c 100644 (file)
@@ -336,16 +336,17 @@ void processArgs( int argc, const char **argv, InputData &id )
                                printStatistics = true;
                                break;
                        case '-': {
-                               char *eq = strchr( pc.paramArg, '=' );
+                               char *arg = strdup( pc.paramArg );
+                               char *eq = strchr( arg, '=' );
 
                                if ( eq != 0 )
                                        *eq++ = 0;
 
-                               if ( strcmp( pc.paramArg, "help" ) == 0 )
+                               if ( strcmp( arg, "help" ) == 0 )
                                        usage();
-                               else if ( strcmp( pc.paramArg, "version" ) == 0 )
+                               else if ( strcmp( arg, "version" ) == 0 )
                                        version();
-                               else if ( strcmp( pc.paramArg, "error-format" ) == 0 ) {
+                               else if ( strcmp( arg, "error-format" ) == 0 ) {
                                        if ( eq == 0 )
                                                error() << "expecting '=value' for error-format" << endl;
                                        else if ( strcmp( eq, "gnu" ) == 0 )
@@ -355,12 +356,13 @@ void processArgs( int argc, const char **argv, InputData &id )
                                        else
                                                error() << "invalid value for error-format" << endl;
                                }
-                               else if ( strcmp( pc.paramArg, "rbx" ) == 0 )
+                               else if ( strcmp( arg, "rbx" ) == 0 )
                                        rubyImpl = Rubinius;
                                else {
                                        error() << "--" << pc.paramArg << 
                                                        " is an invalid argument" << endl;
                                }
+                               free( arg );
                                break;
                        }