texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Avoid warn_unused_result warning from gcc


From: Gavin D. Smith
Subject: branch master updated: Avoid warn_unused_result warning from gcc
Date: Wed, 16 Feb 2022 15:58:15 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 21ae0666fb Avoid warn_unused_result warning from gcc
21ae0666fb is described below

commit 21ae0666fbac38e106681202178e06787d456bdc
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Feb 16 20:58:06 2022 +0000

    Avoid warn_unused_result warning from gcc
    
    * tp/Texinfo/XS/text.c, tp/Texinfo/XS/parsetexi/errors.c
    (xasprintf, xvasprintf): New wrapper functions for
    asprintf and vasprintf.  Abort if functions failed.
---
 ChangeLog                         |  8 ++++++++
 tp/Texinfo/XS/parsetexi/errors.c  | 24 ++++++++++++++++++++++--
 tp/Texinfo/XS/parsetexi/errors.h  |  4 ++++
 tp/Texinfo/XS/parsetexi/indices.c |  4 ++--
 tp/Texinfo/XS/parsetexi/input.c   |  4 ++--
 tp/Texinfo/XS/parsetexi/parser.c  |  6 +++---
 tp/Texinfo/XS/parsetexi/text.c    |  6 ++----
 tp/Texinfo/XS/text.c              |  3 ++-
 8 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6ac799562a..1de13ac5d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-02-16  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Avoid warn_unused_result warning from gcc
+
+       * tp/Texinfo/XS/text.c, tp/Texinfo/XS/parsetexi/errors.c
+       (xasprintf, xvasprintf): New wrapper functions for
+       asprintf and vasprintf.  Abort if functions failed.
+
 2022-02-16  Gavin Smith  <gavinsmith0123@gmail.com>
 
        @image top page margin
diff --git a/tp/Texinfo/XS/parsetexi/errors.c b/tp/Texinfo/XS/parsetexi/errors.c
index 522bd3434d..8633979e9d 100644
--- a/tp/Texinfo/XS/parsetexi/errors.c
+++ b/tp/Texinfo/XS/parsetexi/errors.c
@@ -28,6 +28,26 @@
 #include "input.h"
 #include "text.h"
 
+/* wrappers for asprintf and vasprintf */
+int
+xvasprintf (char **ptr, const char *template, va_list ap)
+{
+  int ret;
+  ret = vasprintf (ptr, template, ap);
+  if (ret < 0)
+    abort (); /* out of memory */
+  return ret;
+}
+
+int
+xasprintf (char **ptr, const char *template, ...)
+{
+  va_list v;
+  va_start (v, template);
+  return xvasprintf (ptr, template, v);
+}
+
+
 void bug (char *message)
 {
   fprintf (stderr, "texi2any (XS parser): bug: %s\n", message);
@@ -56,9 +76,9 @@ line_error_internal (enum error_type type, LINE_NR 
*cmd_line_nr,
 {
   char *message;
 #ifdef ENABLE_NLS
-  vasprintf (&message, gettext(format), v);
+  xvasprintf (&message, gettext(format), v);
 #else
-  vasprintf (&message, format, v);
+  xvasprintf (&message, format, v);
 #endif
   if (!message) fatal ("vasprintf failed");
 
diff --git a/tp/Texinfo/XS/parsetexi/errors.h b/tp/Texinfo/XS/parsetexi/errors.h
index 733d1372a5..e9c0682f20 100644
--- a/tp/Texinfo/XS/parsetexi/errors.h
+++ b/tp/Texinfo/XS/parsetexi/errors.h
@@ -3,6 +3,10 @@
 #define ERRORS_H
 
 #include "tree_types.h"
+#include <stdarg.h>
+
+int xasprintf (char **ptr, const char *template, ...);
+int xvasprintf (char **ptr, const char *template, va_list ap);
 
 void fatal (char *);
 void bug (char *);
diff --git a/tp/Texinfo/XS/parsetexi/indices.c 
b/tp/Texinfo/XS/parsetexi/indices.c
index 896fd9b750..6e86a164f3 100644
--- a/tp/Texinfo/XS/parsetexi/indices.c
+++ b/tp/Texinfo/XS/parsetexi/indices.c
@@ -1,4 +1,4 @@
-/* Copyright 2010-2019 Free Software Foundation, Inc.
+/* Copyright 2010-2022 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -121,7 +121,7 @@ add_index (char *name, int in_code)
   idx = add_index_internal (name, in_code);
 
   /* For example, "rq" -> "rqindex". */
-  asprintf (&cmdname, "%s%s", name, "index");
+  xasprintf (&cmdname, "%s%s", name, "index");
   add_index_command (cmdname, idx);
   free (cmdname);
 }
diff --git a/tp/Texinfo/XS/parsetexi/input.c b/tp/Texinfo/XS/parsetexi/input.c
index 81120f81a0..2199db9aec 100644
--- a/tp/Texinfo/XS/parsetexi/input.c
+++ b/tp/Texinfo/XS/parsetexi/input.c
@@ -337,7 +337,7 @@ next_text (void)
                 {
                   /* Add a newline at the end of the file if one is missing. */
                   char *line2;
-                  asprintf (&line2, "%s\n", line);
+                  xasprintf (&line2, "%s\n", line);
                   free (line);
                   line = line2;
                 }
@@ -554,7 +554,7 @@ locate_include_file (char *filename)
     {
       for (i = 0; i < include_dirs_number; i++)
         {
-          asprintf (&fullpath, "%s/%s", include_dirs[i], filename);
+          xasprintf (&fullpath, "%s/%s", include_dirs[i], filename);
           status = stat (fullpath, &dummy);
           if (status == 0)
             return fullpath;
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 4faab5ce40..ac5f104a9d 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1,4 +1,4 @@
-/* Copyright 2010-2019 Free Software Foundation, Inc.
+/* Copyright 2010-2022 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1437,12 +1437,12 @@ superfluous_arg:
                   k = lookup_extra (current, "spaces");
                   if (!k)
                     {
-                      asprintf (&s, "%.*s", (int) (p - line), line);
+                      xasprintf (&s, "%.*s", (int) (p - line), line);
                       add_extra_string (current, "spaces", s);
                     }
                   else
                     {
-                      asprintf (&s, "%s%.*s",
+                      xasprintf (&s, "%s%.*s",
                                 (char *) k->value,
                                 (int) (p - line), p);
                       free (k->value);
diff --git a/tp/Texinfo/XS/parsetexi/text.c b/tp/Texinfo/XS/parsetexi/text.c
index 224464f529..7427560c5f 100644
--- a/tp/Texinfo/XS/parsetexi/text.c
+++ b/tp/Texinfo/XS/parsetexi/text.c
@@ -1,4 +1,4 @@
-/* Copyright 2014-2021 Free Software Foundation, Inc.
+/* Copyright 2014-2022 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -31,8 +31,6 @@ text_alloc (TEXT *t, size_t len)
       t->space = t->end + len;
       if (t->space < 10)
         t->space = 10;
-      /* This makes a huge difference under Valgrind, is not noticable
-         otherwise. */
       t->space *= 2;
       t->text = realloc (t->text, t->space);
       if (!t->text)
@@ -47,7 +45,7 @@ text_printf (TEXT *t, char *format, ...)
   char *s;
 
   va_start (v, format);
-  vasprintf (&s, format, v);
+  xvasprintf (&s, format, v);
   text_append (t, s);
   free (s);
   va_end (v);
diff --git a/tp/Texinfo/XS/text.c b/tp/Texinfo/XS/text.c
index 6baf8da3df..d24b69d2f5 100644
--- a/tp/Texinfo/XS/text.c
+++ b/tp/Texinfo/XS/text.c
@@ -46,7 +46,8 @@ text_printf (TEXT *t, char *format, ...)
   char *s;
 
   va_start (v, format);
-  vasprintf (&s, format, v);
+  if (vasprintf (&s, format, v) < 0)
+    abort ();  /* out of memory */
   text_append (t, s);
   free (s);
   va_end (v);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]