[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 09/18: [grohtml]: Quieten -Wformat-overflow warnings.
From: |
G. Branden Robinson |
Subject: |
[groff] 09/18: [grohtml]: Quieten -Wformat-overflow warnings. |
Date: |
Sun, 2 Jan 2022 10:33:58 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit b07a868fadabd49586b378e39e9ff32418fe5662
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Dec 31 06:19:03 2021 +1100
[grohtml]: Quieten -Wformat-overflow warnings.
* src/devices/grohtml/html.h (INT_HEXDIGITS): Add new constant to store
the maximum possible quantity of digits in the hexadecimal
representation of an `int`.
* src/devices/grohtml/html-text.cpp (html_text::issue_tag):
* src/devices/grohtml/post-html.cpp (html_printer::do_body): Guard
against format string overflow by large integers in RGB color channel
specifications; in a *printf format string, the precision (like the
field width) is a _minimum_. Quietens `-Wformat-overflow` warnings
from GCC 8.3.
---
ChangeLog | 13 +++++++++++++
src/devices/grohtml/html-text.cpp | 2 +-
src/devices/grohtml/html.h | 2 ++
src/devices/grohtml/post-html.cpp | 2 +-
4 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3b30b3e7..5b8b9d24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-12-31 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/devices/grohtml/html.h (INT_HEXDIGITS): Add new constant
+ to store the maximum possible quantity of digits in the
+ hexadecimal representation of an `int`.
+
+ * src/devices/grohtml/html-text.cpp (html_text::issue_tag):
+ * src/devices/grohtml/post-html.cpp (html_printer::do_body):
+ Guard against format string overflow by large integers in RGB
+ color channel specifications; in a *printf format string, the
+ precision (like the field width) is a _minimum_. Quietens
+ `-Wformat-overflow` warnings from GCC 8.3.
+
2021-12-30 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/preproc/html/pre-html.cpp (get_image_generator): Clarify
diff --git a/src/devices/grohtml/html-text.cpp
b/src/devices/grohtml/html-text.cpp
index 19ceb9e4..b07cbe7a 100644
--- a/src/devices/grohtml/html-text.cpp
+++ b/src/devices/grohtml/html-text.cpp
@@ -211,8 +211,8 @@ void html_text::issue_tag (const char *tagname, const char
*arg,
void html_text::issue_color_begin (color *c)
{
+ char buf[(INT_HEXDIGITS * 3) + 1];
unsigned int r, g, b;
- char buf[6+1];
out->put_string("<font color=\"#");
if (c->is_default())
diff --git a/src/devices/grohtml/html.h b/src/devices/grohtml/html.h
index e7883e79..4828646d 100644
--- a/src/devices/grohtml/html.h
+++ b/src/devices/grohtml/html.h
@@ -20,6 +20,8 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#if !defined(HTML_H)
# define HTML_H
+const int INT_HEXDIGITS = 16; // enough for 64-bit ints
+
/*
* class and structure needed to buffer words
*/
diff --git a/src/devices/grohtml/post-html.cpp
b/src/devices/grohtml/post-html.cpp
index e7162179..0d8b21f1 100644
--- a/src/devices/grohtml/post-html.cpp
+++ b/src/devices/grohtml/post-html.cpp
@@ -4879,8 +4879,8 @@ void html_printer::do_body (void)
if (background == NULL)
fputs("<body>\n\n", stdout);
else {
+ char buf[(INT_HEXDIGITS * 3) + 1];
unsigned int r, g, b;
- char buf[6+1];
background->get_rgb(&r, &g, &b);
// we have to scale 0..0xFFFF to 0..0xFF
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 09/18: [grohtml]: Quieten -Wformat-overflow warnings.,
G. Branden Robinson <=