[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 03/03: [libgroff,pic]: Use `strsave()`, not `strdup()`.
From: |
G. Branden Robinson |
Subject: |
[groff] 03/03: [libgroff,pic]: Use `strsave()`, not `strdup()`. |
Date: |
Sun, 7 Nov 2021 03:06:05 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 5b7fee5d6392edf90dc1f0fa7d013f36fea5964c
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Nov 7 09:40:14 2021 +1100
[libgroff,pic]: Use `strsave()`, not `strdup()`.
* src/libs/libgroff/font.cpp (font::load_desc): Do it. Also emit
shorter diagnostic if `strsave()` returned a null pointer.
* src/preproc/pic/troff.cpp (troff_output::set_location): Do it.
groff has for 30+ years used its own alternative to strdup() called
strsave(). The reason for this is not clear to me but the code has been
consistent. This change fixes `strdup()`s I introduced in ee0942bd (2
November) and 423e3c0b (28 September), respectively.
---
ChangeLog | 8 ++++++++
src/libs/libgroff/font.cpp | 11 ++++++++---
src/preproc/pic/troff.cpp | 2 +-
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9758a40..f349e1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2021-11-07 G. Branden Robinson <g.branden.robinson@gmail.com>
+ [libgroff,pic]: Use `strsave()`, not `strdup()`.
+
+ * src/libs/libgroff/font.cpp (font::load_desc): Do it. Also
+ emit shorter diagnostic if `strsave()` returned a null pointer.
+ * src/preproc/pic/troff.cpp (troff_output::set_location): Do it.
+
+2021-11-07 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* src/libs/libgroff/fontfile.cpp (font::open_file): Don't open
user-specified font file names with slashes in them; i.e., don't
traverse directories outside the configured font path. Also
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 2168afa..b7960b7 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -1144,7 +1144,7 @@ bool font::load_desc()
return false;
}
bool found_paper = false;
- char *savedp = strdup(p);
+ char *savedp = strsave(p);
while (p) {
double unscaled_paperwidth, unscaled_paperlength;
if (scan_papersize(p, &papersize, &unscaled_paperlength,
@@ -1157,8 +1157,13 @@ bool font::load_desc()
p = strtok(0, WS);
}
if (!found_paper) {
- t.error("unable to determine a paper format from '%1'", savedp);
- free(savedp);
+ if (0 == savedp)
+ t.error("unable to determine a paper format");
+ else {
+ t.error("unable to determine a paper format from '%1'",
+ savedp);
+ free(savedp);
+ }
return false;
}
free(savedp);
diff --git a/src/preproc/pic/troff.cpp b/src/preproc/pic/troff.cpp
index 3ccd681..810067a 100644
--- a/src/preproc/pic/troff.cpp
+++ b/src/preproc/pic/troff.cpp
@@ -560,7 +560,7 @@ void troff_output::set_location(const char *s, int n)
printf(".lf %d\n", n);
else {
printf(".lf %d %s\n", n, s);
- last_filename = strdup(s);
+ last_filename = strsave(s);
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 03/03: [libgroff,pic]: Use `strsave()`, not `strdup()`.,
G. Branden Robinson <=