apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Hudson <ghud...@MIT.EDU>
Subject Re: [PATCH] Tweaks to checked-in apr_getopt_long
Date Sat, 25 Nov 2000 05:43:36 GMT
> Given the interface we've decided on, the copying of argv seems
> inevitable

Speaking of which, one more itty bitty little tweak I just thought of:
the argv array is traditionally NULL-terminated as well as counted,
and we should preserve that property in the copy.  This isn't
particularly time-critical, though.

Thanks for committing these changes.

Index: getopt.c
===================================================================
RCS file: /home/cvspublic/apr/misc/unix/getopt.c,v
retrieving revision 1.26
diff -u -r1.26 getopt.c
--- getopt.c	2000/11/25 05:14:59	1.26
+++ getopt.c	2000/11/25 05:41:48
@@ -63,9 +63,10 @@
        that's the primary purpose of this function.  But people might
        want to use this function with arrays other than the main argv,
        and we shouldn't touch the caller's data.  So we copy. */
-    (*os)->argv = apr_palloc(cont, argc * sizeof(const char *));
+    (*os)->argv = apr_palloc(cont, (argc + 1) * sizeof(const char *));
     for (i = 0; i < argc; i++)
 	(*os)->argv[i] = argv[i];
+    (*os)->argv[argc] = NULL;
 
     (*os)->interleave = 0;
     (*os)->ind = 1;

Mime
View raw message