]> granicus.if.org Git - graphviz/commitdiff
lefty SFstatAndCheck: use 'size_t' variables when dealing with buffer sizes
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 18 Sep 2021 01:37:57 +0000 (18:37 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Sep 2021 18:00:08 +0000 (11:00 -0700)
Squashes two -Wconversion warnings and improves portability.

cmd/lefty/ws/x11/libfilereq/Draw.c

index 9d79eaf62e47edef952a0157cc1119fdce59df54..9bd1448d54d13471ac4e649555cff37f9c7dae70 100644 (file)
@@ -38,6 +38,7 @@
  */
 
 #include "config.h"
+#include <stddef.h>
 #include <stdio.h>
 #include <stdint.h>
 #include "SFinternal.h"
@@ -200,21 +201,20 @@ static void SFdeleteEntry (SFDir *dir, SFEntry *entry) {
     );
 }
 
-static void SFwriteStatChar (char *name, int last, struct stat *statBuf) {
+static void SFwriteStatChar(char *name, size_t last, struct stat *statBuf) {
     name[last] = SFstatChar (statBuf);
 }
 
 static int SFstatAndCheck (SFDir *dir, SFEntry *entry) {
     struct stat statBuf;
     char        save;
-    int         last;
 
     /* must be restored before returning */
     save = *(dir->path);
     *(dir->path) = 0;
 
     if (!SFchdir (SFcurrentPath)) {
-        last = strlen (entry->real) - 1;
+        size_t last = strlen(entry->real) - 1;
         entry->real[last] = 0;
         entry->statDone = 1;
         if (
@@ -229,9 +229,7 @@ static int SFstatAndCheck (SFDir *dir, SFEntry *entry) {
                 shown = NULL;
                 if (SFfunc (entry->real, &shown, &statBuf)) {
                     if (shown) {
-                        int len;
-
-                        len = strlen (shown);
+                        size_t len = strlen(shown);
                         entry->shown = XtMalloc ((unsigned) (len + 2));
                         strcpy (entry->shown, shown);
                         SFwriteStatChar (entry->shown, len, &statBuf);