]> diplodocus.org Git - nmh/blobdiff - sbr/seq_list.c
fmt_scan(): Avoid undefined behaviour from overlapping strncpy(3).
[nmh] / sbr / seq_list.c
index 268c25944792a1a98e1d614c4dd9f21a2af9190e..0aef35e369730d779e5091214fcbb78fa1726c29 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * seq_list.c -- Get all messages in a sequence and return them
+/* seq_list.c -- Get all messages in a sequence and return them
  *            -- as a space separated list of message ranges.
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
@@ -8,8 +6,11 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "m_name.h"
+#include "seq_list.h"
+#include "seq_getnum.h"
+#include "h/utils.h"
 
 /* allocate this much buffer space at a time */
 #define MAXBUFFER 1024
@@ -40,9 +41,9 @@ seq_list(struct msgs *mp, char *seqname)
     if (!strcmp (current, seqname)) {
        if (mp->curmsg) {       
            snprintf(buffer, len, "%s", m_name(mp->curmsg));
-           return (buffer);
-       } else
-           return (NULL);
+           return buffer;
+       }
+        return NULL;
     }
 
     /* If the folder is empty, just return NULL */
@@ -85,7 +86,7 @@ seq_list(struct msgs *mp, char *seqname)
        if (bp > buffer)
            *bp++ = ' ';
 
-       sprintf(bp, "%s", m_name(i));
+       strcpy(bp, m_name(i));
        bp += strlen(bp);
        j = i;                  /* Remember beginning of message range */
 
@@ -97,9 +98,10 @@ seq_list(struct msgs *mp, char *seqname)
            ;
 
        if (i - j > 1) {
-           sprintf(bp, "-%s", m_name(i - 1));
+            *bp++ = '-';
+           strcpy(bp, m_name(i - 1));
            bp += strlen(bp);
        }
     }
-    return (bp > buffer? buffer : NULL);
+    return bp > buffer ? buffer : NULL;
 }