[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 07/19: src/libs/libgroff/error.cpp: Shun heap allocation.
From: |
G. Branden Robinson |
Subject: |
[groff] 07/19: src/libs/libgroff/error.cpp: Shun heap allocation. |
Date: |
Mon, 8 Nov 2021 18:56:00 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 9a03816123eff2f840db444243e5ba0acd0995b4
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Nov 8 07:52:31 2021 +1100
src/libs/libgroff/error.cpp: Shun heap allocation.
* src/libs/libgroff/error.cpp (do_error_with_file_and_line): Revise to
eliminate `fprintf()` calls, which might perform dynamic memory
allocation, rendering this function unsafe to call after memory
allocation failures. Since this function is near the top of our
diagnostic output call stack, that would be unfortunate. `errprint()`
does not use dynamic allocation, nor do the `i_to_a()` and `ui_to_a()`
functions it calls to format integers.
---
ChangeLog | 11 +++++++++++
src/libs/libgroff/error.cpp | 17 +++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a787dc8..0e87c40 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2021-11-08 G. Branden Robinson <g.branden.robinson@gmail.com>
+ * src/libs/libgroff/error.cpp (do_error_with_file_and_line):
+ Revise to eliminate `fprintf()` calls, which might perform
+ dynamic memory allocation, rendering this function unsafe to
+ call after memory allocation failures. Since this function is
+ near the top of our diagnostic output call stack, that would be
+ unfortunate. `errprint()` does not use dynamic allocation, nor
+ do the `i_to_a()` and `ui_to_a()` functions it calls to format
+ integers.
+
+2021-11-08 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* configure.ac: Add `strdup` to AC_CHECK_FUNCS since we are
using it and the whole point of libgroff's `strsave()` was to
get along without it. But `strdup` has been standardized in
diff --git a/src/libs/libgroff/error.cpp b/src/libs/libgroff/error.cpp
index a06239a..b199072 100644
--- a/src/libs/libgroff/error.cpp
+++ b/src/libs/libgroff/error.cpp
@@ -41,17 +41,22 @@ static void do_error_with_file_and_line(const char
*filename,
{
bool need_space = false;
if (program_name) {
- fprintf(stderr, "%s:", program_name);
+ fputs(program_name, stderr);
need_space = true;
}
if (filename != 0) {
if (strcmp(filename, "-") == 0)
filename = "<standard input>";
- fprintf(stderr, "%s", filename);
- if (source_filename != 0)
- fprintf(stderr, ":(%s)", source_filename);
- if (lineno > 0)
- fprintf(stderr, ":%d", lineno);
+ fputs(filename, stderr);
+ if (source_filename != 0) {
+ fputs(":(", stderr);
+ fputs(source_filename, stderr);
+ fputc(')', stderr);
+ }
+ if (lineno > 0) {
+ fputc(':', stderr);
+ errprint("%1", lineno);
+ }
fputc(':', stderr);
need_space = true;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 07/19: src/libs/libgroff/error.cpp: Shun heap allocation.,
G. Branden Robinson <=