]> granicus.if.org Git - neomutt/commitdiff
Use sizeof() rather than constants
authorRichard Russon <rich@flatcap.org>
Tue, 29 May 2018 14:32:05 +0000 (15:32 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 6 Jun 2018 14:46:22 +0000 (15:46 +0100)
conn/ssl.c
hcache/bdb.c
init.c
mh.c
mutt/file.c
mutt_lua.c
muttlib.c
pattern.c

index c6cc17e8fd7e9b7d1e5527d740dd51bdc0ec9593..f24bd6d06ea791acadf348cb2571d947cfd3f0af 100644 (file)
@@ -433,7 +433,7 @@ static void x509_fingerprint(char *s, int l, X509 *cert, const EVP_MD *(*hashfun
     for (unsigned int i = 0; i < n; i++)
     {
       char ch[8];
-      snprintf(ch, 8, "%02X%s", md[i], (i % 2 ? " " : ""));
+      snprintf(ch, sizeof(ch), "%02X%s", md[i], (i % 2 ? " " : ""));
       mutt_str_strcat(s, l, ch);
     }
   }
index b1fc9e90801518ade2db67ed07ee3ade3b45500e..ed785f61d0ff40bc8e7ff66b5731aeb5325bae78 100644 (file)
@@ -94,7 +94,7 @@ static void *hcache_bdb_open(const char *path)
   if (mutt_str_atoi(HeaderCachePagesize, &pagesize) < 0 || pagesize <= 0)
     pagesize = 16384;
 
-  snprintf(ctx->lockfile, _POSIX_PATH_MAX, "%s-lock-hack", path);
+  snprintf(ctx->lockfile, sizeof(ctx->lockfile), "%s-lock-hack", path);
 
   ctx->fd = open(ctx->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
   if (ctx->fd < 0)
diff --git a/init.c b/init.c
index d5431751f43df23dd87d4a2c4693cbe77aa8da4b..7538fe67d616ffeb36e792bb9016cea1644fdf15 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1216,7 +1216,7 @@ static int source_rc(const char *rcfile_path, struct Buffer *err)
 
   pid_t pid;
 
-  mutt_str_strfcpy(rcfile, rcfile_path, PATH_MAX);
+  mutt_str_strfcpy(rcfile, rcfile_path, sizeof(rcfile));
 
   rcfilelen = mutt_str_strlen(rcfile);
   if (rcfilelen == 0)
diff --git a/mh.c b/mh.c
index fb32d9a18b966e9b57af07f7b3abb0371583c342..df3b80a0ec45b9bd0199ba16880440fa8e8d9fb6 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -380,7 +380,7 @@ static int mh_mkstemp(struct Context *dest, FILE **fp, char **tgt)
   omask = umask(mh_umask(dest));
   while (true)
   {
-    snprintf(path, _POSIX_PATH_MAX, "%s/.neomutt-%s-%d-%" PRIu64, dest->path,
+    snprintf(path, sizeof(path), "%s/.neomutt-%s-%d-%" PRIu64, dest->path,
              NONULL(ShortHostname), (int) getpid(), mutt_rand64());
     fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
     if (fd == -1)
@@ -1539,7 +1539,7 @@ static int maildir_msg_open_new(struct Context *ctx, struct Message *msg,
   omask = umask(mh_umask(ctx));
   while (true)
   {
-    snprintf(path, _POSIX_PATH_MAX, "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s", ctx->path, subdir,
+    snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s", ctx->path, subdir,
              (long long) time(NULL), mutt_rand64(), NONULL(ShortHostname), suffix);
 
     mutt_debug(2, "Trying %s.\n", path);
@@ -1622,9 +1622,9 @@ static int md_commit_message(struct Context *ctx, struct Message *msg, struct He
   /* construct a new file name. */
   while (true)
   {
-    snprintf(path, _POSIX_PATH_MAX, "%s/%lld.R%" PRIu64 ".%s%s", subdir,
+    snprintf(path, sizeof(path), "%s/%lld.R%" PRIu64 ".%s%s", subdir,
              (long long) time(NULL), mutt_rand64(), NONULL(ShortHostname), suffix);
-    snprintf(full, _POSIX_PATH_MAX, "%s/%s", ctx->path, path);
+    snprintf(full, sizeof(full), "%s/%s", ctx->path, path);
 
     mutt_debug(2, "renaming %s to %s.\n", msg->path, full);
 
@@ -1793,8 +1793,8 @@ static int mh_rewrite_message(struct Context *ctx, int msgno)
   {
     char oldpath[_POSIX_PATH_MAX];
     char partpath[_POSIX_PATH_MAX];
-    snprintf(oldpath, _POSIX_PATH_MAX, "%s/%s", ctx->path, h->path);
-    mutt_str_strfcpy(partpath, h->path, _POSIX_PATH_MAX);
+    snprintf(oldpath, sizeof(oldpath), "%s/%s", ctx->path, h->path);
+    mutt_str_strfcpy(partpath, h->path, sizeof(partpath));
 
     if (ctx->magic == MUTT_MAILDIR)
       rc = md_commit_message(ctx, dest, h);
@@ -1827,7 +1827,7 @@ static int mh_rewrite_message(struct Context *ctx, int msgno)
     if (ctx->magic == MUTT_MH && rc == 0)
     {
       char newpath[_POSIX_PATH_MAX];
-      snprintf(newpath, _POSIX_PATH_MAX, "%s/%s", ctx->path, h->path);
+      snprintf(newpath, sizeof(newpath), "%s/%s", ctx->path, h->path);
       rc = mutt_file_safe_rename(newpath, oldpath);
       if (rc == 0)
         mutt_str_replace(&h->path, partpath);
index 4ee443930f948795318badb6aeff89ae0cc6633e..2b07138eaa5c3d878af9de6d59ae187042c95e6d 100644 (file)
@@ -1320,11 +1320,11 @@ int mutt_file_to_absolute_path(char *path, const char *reference)
   }
 
   char *dirpath = mutt_file_dirname(reference);
-  mutt_str_strfcpy(abs_path, dirpath, PATH_MAX);
+  mutt_str_strfcpy(abs_path, dirpath, sizeof(abs_path));
   FREE(&dirpath);
   mutt_str_strncat(abs_path, sizeof(abs_path), "/", 1); /* append a / at the end of the path */
 
-  path_len = PATH_MAX - strlen(path);
+  path_len = sizeof(abs_path) - strlen(path);
 
   mutt_str_strncat(abs_path, sizeof(abs_path), path, path_len > 0 ? path_len : 0);
 
index 8b4b600cf580061dbabbc3374d5bd458c000dddd..e69f4b68816ac215646e78df953880dc303c2722 100644 (file)
@@ -323,7 +323,7 @@ static void lua_expose_command(void *p, const struct Command *cmd)
 {
   lua_State *l = (lua_State *) p;
   char buf[LONG_STRING];
-  snprintf(buf, LONG_STRING, "mutt.command.%s = function (...); mutt.call('%s', ...); end",
+  snprintf(buf, sizeof(buf), "mutt.command.%s = function (...); mutt.call('%s', ...); end",
            cmd->name, cmd->name);
   (void) luaL_dostring(l, buf);
 }
index e557548fad0872db28c28aa4367206213d11da4f..eb0ffce8883a2f16aee2815793d520382dd022a3 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1518,7 +1518,7 @@ size_t mutt_realpath(char *buf)
   if (realpath(buf, s) == NULL)
     return 0;
 
-  return mutt_str_strfcpy(buf, s, PATH_MAX);
+  return mutt_str_strfcpy(buf, s, sizeof(s));
 }
 
 /**
index 47007846314a2fe894d72cf6e38d7702744b3790..32b830f70cd03bf7fea1464064ad9cf080ea1cae 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -1491,7 +1491,7 @@ static int match_content_type(const struct Pattern *pat, struct Body *b)
   if (!b)
     return 0;
 
-  snprintf(buffer, STRING, "%s/%s", TYPE(b), b->subtype);
+  snprintf(buffer, sizeof(buffer), "%s/%s", TYPE(b), b->subtype);
 
   if (patmatch(pat, buffer) == 0)
     return 1;