[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: wrapper for asprintf
From: |
Gavin D. Smith |
Subject: |
branch master updated: wrapper for asprintf |
Date: |
Mon, 11 Apr 2022 07:08:49 -0400 |
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 7cf609a906 wrapper for asprintf
7cf609a906 is described below
commit 7cf609a90660e537ae714ad846ab24206aa41b40
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Mon Apr 11 12:08:41 2022 +0100
wrapper for asprintf
* info/util.c (xasprintf): New function to wrap asprintf and
avoid compiler warnings due to unused return values. Use everywhere.
---
ChangeLog | 7 +++++++
info/dir.c | 6 +++---
info/filesys.c | 2 +-
info/footnotes.c | 2 +-
info/indices.c | 10 +++++-----
info/info.c | 6 +++---
info/info.h | 4 +++-
info/m-x.c | 4 ++--
info/session.c | 16 ++++++++--------
info/util.c | 19 +++++++++++++++++++
info/variables.c | 4 ++--
11 files changed, 54 insertions(+), 26 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 85d58136d6..5979ff427a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-04-11 Gavin Smith <gavinsmith0123@gmail.com>
+
+ wrapper for asprintf
+
+ * info/util.c (xasprintf): New function to wrap asprintf and
+ avoid compiler warnings due to unused return values. Use everywhere.
+
2022-04-11 Gavin Smith <gavinsmith0123@gmail.com>
* doc/texinfo.texi
diff --git a/info/dir.c b/info/dir.c
index 0752caa39b..eaa2c405d0 100644
--- a/info/dir.c
+++ b/info/dir.c
@@ -89,7 +89,7 @@ build_dir_node (void)
/* Space for an appended compressed file extension, like ".gz". */
#define PADDING "XXXXXXXXX"
- len = asprintf (&fullpath, "%s/dir%s", this_dir, PADDING);
+ len = xasprintf (&fullpath, "%s/dir%s", this_dir, PADDING);
fullpath[len - strlen(PADDING)] = '\0';
result = info_check_compressed (fullpath, &finfo);
@@ -248,13 +248,13 @@ dir_entry_of_infodir (char *label, char *searchdir)
NODE *dir_node;
REFERENCE *entry;
- len = asprintf (&dir_fullpath, "%s/dir%s", searchdir, PADDING);
+ len = xasprintf (&dir_fullpath, "%s/dir%s", searchdir, PADDING);
dir_fullpath[len - strlen(PADDING)] = '\0';
if (!IS_ABSOLUTE(dir_fullpath))
{
char *tmp;
- asprintf (&tmp, "./%s", dir_fullpath);
+ xasprintf (&tmp, "./%s", dir_fullpath);
free (dir_fullpath);
dir_fullpath = tmp;
}
diff --git a/info/filesys.c b/info/filesys.c
index bc6a63ecfe..5f27f58b6b 100644
--- a/info/filesys.c
+++ b/info/filesys.c
@@ -164,7 +164,7 @@ info_file_find_next_in_path (char *filename, int
*path_index, struct stat *finfo
{
/* Prefix "./" to it. */
char *s;
- asprintf (&s, "%s%s", "./", with_extension);
+ xasprintf (&s, "%s%s", "./", with_extension);
free (with_extension);
return s;
}
diff --git a/info/footnotes.c b/info/footnotes.c
index d0cc520a6a..4eddc2478b 100644
--- a/info/footnotes.c
+++ b/info/footnotes.c
@@ -120,7 +120,7 @@ make_footnotes_node (NODE *node)
char *header;
long text_start = fn_start;
- asprintf (&header,
+ xasprintf (&header,
"*** Footnotes appearing in the node '%s' ***\n",
node->nodename);
diff --git a/info/indices.c b/info/indices.c
index 79347eaa25..5dfcf3091c 100644
--- a/info/indices.c
+++ b/info/indices.c
@@ -652,9 +652,9 @@ DECLARE_INFO_COMMAND (info_index_apropos,
struct text_buffer message;
if (index_search)
- asprintf (&prompt, "%s [%s]: ", _("Index apropos"), index_search);
+ xasprintf (&prompt, "%s [%s]: ", _("Index apropos"), index_search);
else
- asprintf (&prompt, "%s: ", _("Index apropos"));
+ xasprintf (&prompt, "%s: ", _("Index apropos"));
line = info_read_in_echo_area (prompt);
free (prompt);
@@ -850,7 +850,7 @@ create_virtual_index (FILE_BUFFER *file_buffer, char
*index_search)
}
node = info_create_node ();
- asprintf (&node->nodename, "Index for '%s'", index_search);
+ xasprintf (&node->nodename, "Index for '%s'", index_search);
node->fullpath = file_buffer->filename;
node->contents = text_buffer_base (&text);
node->nodelen = text_buffer_off (&text) - 1;
@@ -887,9 +887,9 @@ DECLARE_INFO_COMMAND (info_virtual_index,
/* Default to last search if there is one. */
if (index_search)
- asprintf (&prompt, "%s [%s]: ", _("Index topic"), index_search);
+ xasprintf (&prompt, "%s [%s]: ", _("Index topic"), index_search);
else
- asprintf (&prompt, "%s: ", _("Index topic"));
+ xasprintf (&prompt, "%s: ", _("Index topic"));
line = info_read_maybe_completing (prompt, index_index);
free (prompt);
diff --git a/info/info.c b/info/info.c
index df609b1d0f..63ea96f5f1 100644
--- a/info/info.c
+++ b/info/info.c
@@ -183,7 +183,7 @@ get_initial_file (int *argc, char ***argv, char **error)
/* Prefix "./" to the filename to prevent a lookup
in INFOPATH. */
char *s;
- asprintf (&s, "%s%s", "./", user_filename);
+ xasprintf (&s, "%s%s", "./", user_filename);
free (user_filename);
user_filename = s;
}
@@ -275,7 +275,7 @@ get_initial_file (int *argc, char ***argv, char **error)
return;
}
else
- asprintf (error, _("No menu item '%s' in node '%s'"),
+ xasprintf (error, _("No menu item '%s' in node '%s'"),
(*argv)[0], "(dir)Top");
}
@@ -413,7 +413,7 @@ add_initial_nodes (int argc, char **argv, char **error)
if (!node_nodename)
{
free (*error);
- asprintf (error, _("Cannot find node '%s'"),
+ xasprintf (error, _("Cannot find node '%s'"),
user_nodenames[i]);
continue;
}
diff --git a/info/info.h b/info/info.h
index 7468a072fb..8082725146 100644
--- a/info/info.h
+++ b/info/info.h
@@ -1,4 +1,4 @@
-/* info.h -- Header file which includes all of the other headers.
+/* info.h -- Header file included everywhere
Copyright 1993-2022 Free Software Foundation, Inc.
@@ -32,6 +32,8 @@ typedef char *CFunction ();
#include "mbiter.h"
#include "mbchar.h"
+int xasprintf (char **ptr, const char *template, ...);
+
extern char *program_name;
#if !defined (whitespace)
diff --git a/info/m-x.c b/info/m-x.c
index 413c219544..669d999738 100644
--- a/info/m-x.c
+++ b/info/m-x.c
@@ -99,9 +99,9 @@ DECLARE_INFO_COMMAND (info_execute_command,
abort();
if (info_explicit_arg || count != 1)
- asprintf (&prompt, "%d %s ", count, keys);
+ xasprintf (&prompt, "%d %s ", count, keys);
else
- asprintf (&prompt, "%s ", keys);
+ xasprintf (&prompt, "%s ", keys);
/* Ask the completer to read a reference for us. */
line = read_function_name (prompt, window);
diff --git a/info/session.c b/info/session.c
index f06318a49c..cbe4cc3a33 100644
--- a/info/session.c
+++ b/info/session.c
@@ -2765,7 +2765,7 @@ info_follow_menus (NODE *initial_node, char **menus, char
**error,
if (error)
{
free (*error);
- asprintf (error, _("No menu in node '%s'"),
+ xasprintf (error, _("No menu in node '%s'"),
node_printed_rep (initial_node));
}
debug (3, ("no menu found"));
@@ -2787,7 +2787,7 @@ info_follow_menus (NODE *initial_node, char **menus, char
**error,
if (error)
{
free (*error);
- asprintf (error, _("No menu item '%s' in node '%s'"),
+ xasprintf (error, _("No menu item '%s' in node '%s'"),
arg, node_printed_rep (initial_node));
}
debug (3, ("no entry found"));
@@ -2811,7 +2811,7 @@ info_follow_menus (NODE *initial_node, char **menus, char
**error,
if (error)
{
free (*error);
- asprintf (error,
+ xasprintf (error,
_("Unable to find node referenced by '%s' in '%s'"),
entry->label,
node_printed_rep (initial_node));
@@ -3392,8 +3392,8 @@ find_invocation_node_by_nodename (FILE_BUFFER *fb, char
*program)
if (!n)
return 0;
- asprintf (&try1, "Invoking %s", program);
- asprintf (&try2, "%s invocation", program);
+ xasprintf (&try1, "Invoking %s", program);
+ xasprintf (&try2, "%s invocation", program);
for (; *n; n++)
{
if ((*n)->nodename
@@ -4235,13 +4235,13 @@ ask_for_search_string (int case_sensitive, int
use_regex, int direction)
char *line, *prompt;
if (search_string)
- asprintf (&prompt, _("%s%s%s [%s]: "),
+ xasprintf (&prompt, _("%s%s%s [%s]: "),
use_regex ? _("Regexp search") : _("Search"),
case_sensitive ? _(" case-sensitively") : "",
direction < 0 ? _(" backward") : "",
search_string);
else
- asprintf (&prompt, _("%s%s%s: "),
+ xasprintf (&prompt, _("%s%s%s: "),
use_regex ? _("Regexp search") : _("Search"),
case_sensitive ? _(" case-sensitively") : "",
direction < 0 ? _(" backward") : "");
@@ -4631,7 +4631,7 @@ DECLARE_INFO_COMMAND (info_tree_search,
/* TODO: Display manual name */
/* TRANSLATORS: %s is the title of a node. */
- asprintf (&prompt, _("Search under %s: "),
+ xasprintf (&prompt, _("Search under %s: "),
window->node->nodename);
line = info_read_in_echo_area (prompt); free (prompt);
if (!line)
diff --git a/info/util.c b/info/util.c
index 3e531559fd..03c8e9fe4a 100644
--- a/info/util.c
+++ b/info/util.c
@@ -20,6 +20,25 @@
#include "util.h"
#include "tag.h"
+/* wrapper for asprintf */
+static 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);
+}
+
/* Return the file buffer which belongs to WINDOW's node. */
FILE_BUFFER *
file_buffer_of_window (WINDOW *window)
diff --git a/info/variables.c b/info/variables.c
index 72aebb1223..52e3f5c28a 100644
--- a/info/variables.c
+++ b/info/variables.c
@@ -229,7 +229,7 @@ DECLARE_INFO_COMMAND (describe_variable, _("Explain the use
of a variable"))
return;
if (var->choices)
- asprintf (&description, "%s (%s): %s.",
+ xasprintf (&description, "%s (%s): %s.",
var->name,
var->value == &highlight_searches
? on_off_choices[match_rendition.mask != 0]
@@ -237,7 +237,7 @@ DECLARE_INFO_COMMAND (describe_variable, _("Explain the use
of a variable"))
? rendition_to_string (var->value)
: var->choices[*(int *)var->value], _(var->doc));
else
- asprintf (&description, "%s (%d): %s.",
+ xasprintf (&description, "%s (%d): %s.",
var->name, *(int *)var->value, _(var->doc));
window_message_in_echo_area ("%s", description);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: wrapper for asprintf,
Gavin D. Smith <=