[Pkg-gnupg-commit] [gnupg2] 185/241: common: Fix off-by-one access in the new format_text.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Dec 9 20:32:14 UTC 2015
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit 61941a984964308b09c7fc1b3438fb99d0b3c917
Author: Werner Koch <wk at gnupg.org>
Date: Thu Nov 26 18:04:54 2015 +0100
common: Fix off-by-one access in the new format_text.
* common/stringhelp.c (format_text): Use existsing fucntion to trim
trailing spaces. Fix off-by-one access.
Signed-off-by: Werner Koch <wk at gnupg.org>
---
common/stringhelp.c | 10 +++++++---
common/stringhelp.h | 6 ++----
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/common/stringhelp.c b/common/stringhelp.c
index 6748d1e..e8b990a 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -1328,6 +1328,11 @@ strtokenize (const char *string, const char *delim)
return result;
}
+
+/* Format a string so that it fits within about TARGET_COLS columns.
+ If IN_PLACE is 0, then TEXT is copied to a new buffer, which is
+ returned. Otherwise, TEXT is modified in place and returned.
+ Normally, target_cols will be 72 and max_cols is 80. */
char *
format_text (char *text, int in_place, int target_cols, int max_cols)
{
@@ -1448,10 +1453,9 @@ format_text (char *text, int in_place, int target_cols, int max_cols)
}
/* Chop off any trailing space. */
- while (text[strlen (text) - 1] == ' ')
- text[strlen (text) - 1] = '\0';
+ trim_trailing_chars (text, strlen (text), " ");
/* If we inserted the trailing newline, then remove it. */
- if (! copied_last_space && text[strlen (text) - 1] == '\n')
+ if (! copied_last_space && *text && text[strlen (text) - 1] == '\n')
text[strlen (text) - 1] = '\0';
return text;
diff --git a/common/stringhelp.h b/common/stringhelp.h
index 9ff062b..c813662 100644
--- a/common/stringhelp.h
+++ b/common/stringhelp.h
@@ -148,12 +148,10 @@ char **strsplit (char *string, char delim, char replacement, int *count);
/* Tokenize STRING using the set of delimiters in DELIM. */
char **strtokenize (const char *string, const char *delim);
-/* Format a string so that it fits within about TARGET_COLS columns.
- If IN_PLACE is 0, then TEXT is copied to a new buffer, which is
- returned. Otherwise, TEXT is modified in place and returned.
- Normally, target_cols will be 72 and max_cols is 80. */
+/* Format a string so that it fits within about TARGET_COLS columns. */
char *format_text (char *text, int in_place, int target_cols, int max_cols);
+
/*-- mapstrings.c --*/
const char *map_static_macro_string (const char *string);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list