[Pkg-privacy-commits] [irssi-plugin-otr] 190/267: Fix: handle zero length string in rtrim()

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:31 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.

commit c7a1466ec84d8ff7b8ea377970aa20b77f98ecb8
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Tue Jan 29 21:41:18 2013 -0500

    Fix: handle zero length string in rtrim()
    
    Also adds the trim string definition to utils.h
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/utils.c | 11 ++++++++++-
 src/utils.h |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/utils.c b/src/utils.c
index ac77d69..8f82e63 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -42,15 +42,24 @@ static char *ltrim(char *s)
  */
 static char *rtrim(char *s)
 {
+	size_t len;
 	char *back;
 
 	assert(s);
 
-	back = s + strlen(s);
+	len = strlen(s);
+	if (len == 0) {
+		goto end;
+	}
+
+	back = s + len;
 
+	/* Move up to the first non whitespace character. */
 	while (isspace(*--back));
+	/* Remove whitespace(s) from the string. */
 	*(back + 1) = '\0';
 
+end:
 	return s;
 }
 
diff --git a/src/utils.h b/src/utils.h
index 9a8727c..2d2a526 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -28,5 +28,6 @@ int utils_io_extract_smp(const char *data, char **question, char **secret);
 void utils_string_to_upper(char *string);
 int utils_auth_extract_secret(const char *_data, char **secret);
 void utils_hash_parts_to_readable_hash(const char **parts, char *dst);
+char *utils_trim_string(char *s);
 
 #endif /* IRSSI_OTR_UTILS_H */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git



More information about the Pkg-privacy-commits mailing list