Source: nn
Version: 6.7.3-14
Severity: normal
Tags: patch

Dear Maintainer,

>From 7d4406b9160cfbbca4d0b57c922fe48075c8a695 Mon Sep 17 00:00:00 2001
>From: Bjarni Ingi Gislason <bjarn...@rhi.hi.is>
>Date: Tue, 2 Mar 2021 01:09:02 +0000
>Subject: [PATCH] macro.c: add a cast to "ptrdiff_t", use "snprintf()", and
> make an "unsigned char" cast

  Add <stddef.h> and a cast to "ptrdiff_t" to avoid a warning:

macro.c: In function 'm_define':
macro.c:412:48: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
  412 |     return type == 0 ? (char *) macro[cur_m] : (char *) (K_MACRO | 
cur_m);
      |                                                ^

  Use "snprintf()" instead of "sprintf()".

  Add information to the output of "m_error()".

  Cast an integer variable to unsigned character for the function
"isspace()".

Signed-off-by: Bjarni Ingi Gislason <bjarn...@rhi.hi.is>
---
 macro.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/macro.c b/macro.c
index 4037d60..231fe9a 100644
--- a/macro.c
+++ b/macro.c
@@ -5,6 +5,7 @@
  *     Macro parsing and execution.
  */
 
+#include <stddef.h> /* For definition of "ptrdiff_t" */
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
@@ -105,10 +106,11 @@ static int      cur_m;
 static void
 m_error(char *fmt, char *arg)
 {
-    char            buf[80];
+#define    NBUF  80
+    char            buf[NBUF];
 
     if (arg) {
-       sprintf(buf, fmt, arg);
+       snprintf(buf, NBUF, fmt, arg);
        fmt = buf;
     }
     init_message("Error in macro %d: %s", cur_m, fmt);
@@ -409,7 +411,7 @@ out:
     if (f == stdin)
        nn_raw();
     m = NULL;
-    return type == 0 ? (char *) macro[cur_m] : (char *) (K_MACRO | cur_m);
+    return type == 0 ? (char *) macro[cur_m] : (char *) ((ptrdiff_t) (K_MACRO 
| cur_m));
 }
 
 static char    *
@@ -418,7 +420,7 @@ m_get_macro(char *id)
     if (id) {
        cur_m = atoi(id);
        if (cur_m < 0 || cur_m >= NMACRO) {
-           m_error("macro number out of range\n", id);
+           m_error("macro number %s is out of range\n", id);
            return (char *) 0;
        }
     }
@@ -433,7 +435,7 @@ parse_enter_macro(FILE * f, register int c)
     group_header   *gh;
     static char    *last_defined = NULL;
 
-    while (c != EOF && c != NL && (!isascii(c) || isspace(c)))
+    while (c != EOF && c != NL && (!isascii(c) || isspace((unsigned char) c)))
        c = getc(f);
 
     if (c == ')')
@@ -449,7 +451,7 @@ parse_enter_macro(FILE * f, register int c)
     do {
        *gp++ = c;
        c = getc(f);
-    } while (c != EOF && c != ')' && isascii(c) && !isspace(c));
+    } while (c != EOF && c != ')' && isascii(c) && !isspace((unsigned char) 
c));
 
     *gp = NUL;
     if ((gh = lookup(other)))
-- 
2.30.1



-- System Information:
Debian Release: bullseye/sid
  APT prefers testing
  APT policy: (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.9-1 (SMP w/2 CPU threads)
Locale: LANG=is_IS.iso88591, LC_CTYPE=is_IS.iso88591 (charmap=ISO-8859-1), 
LANGUAGE not set
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)

-- debconf information excluded

-- 
Bjarni I. Gislason

Reply via email to