OSDN Git Service

Fix GLOB_DOOFFS initialization bug.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 12 Mar 2015 07:28:43 +0000 (07:28 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 12 Mar 2015 07:28:43 +0000 (07:28 +0000)
mingwrt/ChangeLog
mingwrt/mingwex/glob.c

index 4466b39..ced6660 100644 (file)
@@ -1,3 +1,10 @@
+2015-03-12  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Fix GLOB_DOOFFS initialization bug.
+
+       * mingwex/glob.c (__mingw_glob) [!GLOB_DOOFFS]: Ensure...
+       (gl_data->gl_offs): ...this is properly initialized to zero.
+
 2014-12-28  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Tag all files for release of mingwrt-3.21.
index 6de4880..8b5332a 100644 (file)
@@ -1039,9 +1039,22 @@ __mingw_glob( const char *pattern, int flags, int (*errfn)(), glob_t *gl_data )
   /* Module entry point for the glob() function.
    */
   int status;
+
   /* First, consult the glob "registry", to ensure that the
    * glob data structure passed by the caller, has been properly
-   * initialised.
+   * initialised.  (Note that this implementation gratuitously uses
+   * gl_data->gl_offs, irrespective of specification of GLOB_DOOFFS
+   * in the flags; while the user must accept responsibility for the
+   * initialisation of gl_data->gl_offs when specifying GLOB_DOOFFS,
+   * this is not the case when GLOB_DOOFFS is not specified; in the
+   * latter case, WE must assume the responsibility, ensuring that
+   * the required zero value is assigned BEFORE registration).
+   */
+  if( (gl_data != NULL) && ((flags & GLOB_DOOFFS) == 0) )
+    gl_data->gl_offs = 0;
+
+  /* With this pre-registration requirement satisfied, we may now
+   * proceed to register the provided gl_data structure.
    */
   gl_data = glob_registry( GLOB_INIT, gl_data );