You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Edward Avis <ep...@doc.ic.ac.uk> on 2001/12/04 13:33:17 UTC

Small patch to 1.5.2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

One of the runConfigure.sh scripts in 1.5.2 will sit in an infinite loop
if given an argument it doesn't understand.  This patch fixes it:

- --- samples/runConfigure.orig	Thu Nov 29 18:56:09 2001
+++ samples/runConfigure	Thu Nov 29 19:05:01 2001
@@ -146,6 +146,11 @@

    --)
         shift; break;;
+
+   *)
+	echo "unknown option $1"
+	usage
+        exit ${ERROR_EXIT_CODE};;
    esac
 done


Actually, it would be a good idea to change code looking like

while [ $# -gt 0 ]
    do
    case $1 in
       foo) something; shift;;
       bar) something_else; shift 2;;
    esac
done

to look instead like

while [ $# -gt 0 ]
    do
    first_arg=$1
    shift
    case $first_arg in
        foo) something;;
        bar) something_else; shift;;
    esac
done

That way, you get at least one 'shift' every time through the loop, so
there's no chance of it looping forever if you forget to put shift in
one of the cases (or if you leave out the default case).

Anyway, I hope this utterly trivial patch makes a change from the
tortuous and complicated XML handling you guys must deal with all day
long :-).

- -- 
Ed Avis <ep...@doc.ic.ac.uk>
Finger for PGP key


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8DMKQIMp73jhGogoRAvjFAJ97OlbxQzWQZyzuks58oe++ikqJpgCbBogo
0cFr+PU6OfWZwKDM1bIQ3uc=
=zlxr
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Small patch to 1.5.2

Posted by Tinny Ng <tn...@ca.ibm.com>.
Edward,

But the runConfigure has something like this:
   # Get the command line parameters
   if test -x /usr/bin/getopt; then
   set -- `getopt p:c:x:dm:n:t:r:l:z:h $*`
   else
   set -- `getopts p:c:x:dm:n:t:r:l:z:h `$*``
   fi
   if [ $? != 0 ]
     then
     usage
     exit ${ERROR_EXIT_CODE}
   fi

the "getopt" should be able to catch any invalid argument.  I tested it and
get the following without running into loop:

 > runConfigure -xCC -ud
getopt: Not a recognized flag: u
runConfigure: Helper script to run "configure" for one of the supported
platforms
Usage: runConfigure "options"
       where options may be any of the following:
       -p <platform> (accepts 'aix', 'unixware', 'linux', 'solaris',
'hp-10', 'hp-11', 'os400', 'irix', 'ptx', 'tru64', 'macosx')
       -c <C compiler name> (e.g. gcc, xlc or icc)
       -x <C++ compiler name> (e.g. g++, xlC, or icc)
       -d (specifies that you want to build debug version)
       -h (get help on the above commands)
       -z <extra compiler options>

May be the system utility "getopt" behaves differently on different
platform??

Tinny


Edward Avis wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> One of the runConfigure.sh scripts in 1.5.2 will sit in an infinite loop
> if given an argument it doesn't understand.  This patch fixes it:
>
> - --- samples/runConfigure.orig Thu Nov 29 18:56:09 2001
> +++ samples/runConfigure        Thu Nov 29 19:05:01 2001
> @@ -146,6 +146,11 @@
>
>     --)
>          shift; break;;
> +
> +   *)
> +       echo "unknown option $1"
> +       usage
> +        exit ${ERROR_EXIT_CODE};;
>     esac
>  done
>
> Actually, it would be a good idea to change code looking like
>
> while [ $# -gt 0 ]
>     do
>     case $1 in
>        foo) something; shift;;
>        bar) something_else; shift 2;;
>     esac
> done
>
> to look instead like
>
> while [ $# -gt 0 ]
>     do
>     first_arg=$1
>     shift
>     case $first_arg in
>         foo) something;;
>         bar) something_else; shift;;
>     esac
> done
>
> That way, you get at least one 'shift' every time through the loop, so
> there's no chance of it looping forever if you forget to put shift in
> one of the cases (or if you leave out the default case).
>
> Anyway, I hope this utterly trivial patch makes a change from the
> tortuous and complicated XML handling you guys must deal with all day
> long :-).
>
> - --
> Ed Avis <ep...@doc.ic.ac.uk>
> Finger for PGP key
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iD8DBQE8DMKQIMp73jhGogoRAvjFAJ97OlbxQzWQZyzuks58oe++ikqJpgCbBogo
> 0cFr+PU6OfWZwKDM1bIQ3uc=
> =zlxr
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Small patch to 1.5.2

Posted by Edward Avis <ep...@doc.ic.ac.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 5 Dec 2001, Tinny Ng wrote:

>BTW your patch also apply to src/runConfigure and tests/runConfigure,
>besides samples/runConfigure, right?

Yes, they could also do with a default case.  Thanks for fixing this.

- -- 
Ed Avis <ep...@doc.ic.ac.uk>
Finger for PGP key
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8DlMSIMp73jhGogoRAlsFAJ9lVLH0QL/WSsN74eVPVCEaqMn0zgCfaTIK
phgWa3lntkBQWy1/Yd7/gZ8=
=+Xrt
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Small patch to 1.5.2

Posted by Tinny Ng <tn...@ca.ibm.com>.
Edward,

I think it doesn't hurt to apply your patch.  So I am going to commit it
then.  BTW your patch also apply to src/runConfigure and tests/runConfigure,
besides samples/runConfigure, right?

Thanks!

Tinny

Edward Avis wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I sent in a small patch to fix argument parsing in
> samples/runConfigure, which could get stuck in an infinite loop.
> Tinny Ng suggested that runConfigure uses getopt(1) which should catch
> invalid arguments by itself.
>
> For whatever reason, getopt didn't catch the invalid argument on my
> system (SuSE Linux 7.2).  I'm sorry, I don't remember what the flag was
> but I do know that the runConfigure script sat there in an infinite loop
> and it took a while to figure out and fix the problem.  In other words
> the patch I sent is a fix for a real bug I encountered.
>
> I think the problem may be that the getopt specification at the top gets
> out of sync with the $1-processing loop.  When this happens the loop can
> get stuck.  It would be a good idea to fix the getopt statement at the
> top, but you should also fix the shell loop.  That way when the two
> lists of possible flags get out of sync again, there will be a clear
> error message rather than just hanging.
>
> (Please cc me on replies since I do not read this list.)
>
> - --
> Ed Avis <ep...@doc.ic.ac.uk>
> Finger for PGP key
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iD8DBQE8DkgqIMp73jhGogoRApqSAJ9N++wWipwD/gmUMJ9kDCcS+KKktgCbBLXL
> fM/JfjZIzdgJopA24uXcT3g=
> =OyOT
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Small patch to 1.5.2

Posted by Edward Avis <ep...@doc.ic.ac.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I sent in a small patch to fix argument parsing in
samples/runConfigure, which could get stuck in an infinite loop.
Tinny Ng suggested that runConfigure uses getopt(1) which should catch
invalid arguments by itself.

For whatever reason, getopt didn't catch the invalid argument on my
system (SuSE Linux 7.2).  I'm sorry, I don't remember what the flag was
but I do know that the runConfigure script sat there in an infinite loop
and it took a while to figure out and fix the problem.  In other words
the patch I sent is a fix for a real bug I encountered.

I think the problem may be that the getopt specification at the top gets
out of sync with the $1-processing loop.  When this happens the loop can
get stuck.  It would be a good idea to fix the getopt statement at the
top, but you should also fix the shell loop.  That way when the two
lists of possible flags get out of sync again, there will be a clear
error message rather than just hanging.

(Please cc me on replies since I do not read this list.)

- -- 
Ed Avis <ep...@doc.ic.ac.uk>
Finger for PGP key

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8DkgqIMp73jhGogoRApqSAJ9N++wWipwD/gmUMJ9kDCcS+KKktgCbBLXL
fM/JfjZIzdgJopA24uXcT3g=
=OyOT
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org