]> granicus.if.org Git - graphviz/commitdiff
gvconfig.c: realign alternative for 'glob' with POSIX
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 3 Nov 2021 03:27:11 +0000 (20:27 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 9 Nov 2021 15:10:10 +0000 (07:10 -0800)
If the `glob` system function¹ is available, it is used in this code. If not (on
Windows), an alternative static function is provided. The POSIX spec mandates
only three members of the `glob_t` struct, `gl_pathc`, `gl_pathv`, and
`gl_offs`. This commit realigns the members with their types in the POSIX spec.
This squashes some -Wsign-compare warnings on POSIX platforms.

¹ https://pubs.opengroup.org/onlinepubs/007908799/xsh/glob.html

lib/gvc/gvconfig.c

index cbf14fe0401d6f1251bcea8a6f79b32f603e8b3a..9ca9b64675d1535abe97c909c0f0d6e1650b3595 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <ctype.h>
 #include <stdbool.h>
+#include <stddef.h>
 #include       <string.h>
 
 #ifdef ENABLE_LTDL
@@ -32,7 +33,7 @@
 #define GLOB_NOMATCH    3   /* No matches found.  */
 #define GLOB_NOSORT     4
 typedef struct {
-    int gl_pathc;           /* count of total paths so far */
+    size_t gl_pathc;        /* count of total paths so far */
     char **gl_pathv;        /* list of paths matching pattern */
 } glob_t;
 static void globfree (glob_t* pglob);
@@ -473,7 +474,7 @@ static void config_rescan(GVC_t *gvc, char *config_path)
     FILE *f = NULL;
     glob_t globbuf;
     char *config_glob, *path, *libdir;
-    int i, rc;
+    int rc;
     gvplugin_library_t *library;
 #if defined(DARWIN_DYLIB)
     char *plugin_glob = "libgvplugin_*";
@@ -516,7 +517,7 @@ static void config_rescan(GVC_t *gvc, char *config_path)
     rc = glob(config_glob, 0, NULL, &globbuf);
 #endif
     if (rc == 0) {
-       for (i = 0; i < globbuf.gl_pathc; i++) {
+       for (size_t i = 0; i < globbuf.gl_pathc; i++) {
            if (is_plugin(globbuf.gl_pathv[i])) {
                library = gvplugin_library_load(gvc, globbuf.gl_pathv[i]);
                if (library) {
@@ -525,7 +526,7 @@ static void config_rescan(GVC_t *gvc, char *config_path)
            }
        }
        /* rescan with all libs loaded to check cross dependencies */
-       for (i = 0; i < globbuf.gl_pathc; i++) {
+       for (size_t i = 0; i < globbuf.gl_pathc; i++) {
            if (is_plugin(globbuf.gl_pathv[i])) {
                library = gvplugin_library_load(gvc, globbuf.gl_pathv[i]);
                if (library) {