]> diplodocus.org Git - nmh/blobdiff - uip/ap.c
Fixed all anomalies detected by clang static analyzer (with
[nmh] / uip / ap.c
index f0b0baa98f3e408c80f22c1f3a402918b12710a2..3dd77b171a56bc1b930db8ce54f884df0d193b85 100644 (file)
--- a/uip/ap.c
+++ b/uip/ap.c
@@ -15,7 +15,6 @@
 #define        NADDRS  100
 
 #define        WIDTH   78
-#define        WBUFSIZ BUFSIZ
 
 #define        FORMAT  "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
 
@@ -48,18 +47,12 @@ int
 main (int argc, char **argv)
 {
     int addrp = 0;
-    int width = 0, status = 0;
+    int width = -1, status = 0;
     char *cp, *form = NULL, *format = NULL, *nfs;
     char buf[BUFSIZ], **argp;
     char **arguments, *addrs[NADDRS];
 
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
@@ -115,13 +108,16 @@ main (int argc, char **argv)
     /* get new format string */
     nfs = new_fs (form, format, FORMAT);
 
-    if (width == 0) {
-       if ((width = sc_width ()) < WIDTH / 2)
+    if (width == -1) {
+       if ((width = sc_width ()) < WIDTH / 2) {
+           /* Default:  width of the terminal, but at least WIDTH/2. */
            width = WIDTH / 2;
+       } else if (width == 0) {
+           /* Unlimited width. */
+           width = INT_MAX;
+       }
        width -= 2;
     }
-    if (width > WBUFSIZ)
-       width = WBUFSIZ;
     fmt_compile (nfs, &fmt, 1);
 
     dat[0] = 0;
@@ -150,7 +146,7 @@ process (char *arg, int length)
 {
     int        status = 0;
     register char *cp;
-    char buffer[WBUFSIZ + 1], error[BUFSIZ];
+    char error[BUFSIZ];
     register struct comp *cptr;
     register struct pqpair *p, *q;
     struct pqpair pq;
@@ -173,6 +169,8 @@ process (char *arg, int length)
     }
 
     for (p = pq.pq_next; p; p = q) {
+       charstring_t scanl = charstring_create (length);
+
        cptr = fmt_findcomp ("text");
        if (cptr) {
            if (cptr->c_text)
@@ -188,8 +186,9 @@ process (char *arg, int length)
            p->pq_error = NULL;
        }
 
-       fmt_scan (fmt, buffer, sizeof buffer - 1, length, dat, NULL);
-       fputs (buffer, stdout);
+       fmt_scan (fmt, scanl, length, dat, NULL);
+       fputs (charstring_buffer (scanl), stdout);
+       charstring_free (scanl);
 
        if (p->pq_text)
            free (p->pq_text);