From 445ecf961f018524a4906fdb2ef3ba00598c1453 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 30 Sep 2007 02:16:37 +0000 Subject: [PATCH] fixed a bug where UTIL_ReplaceAll() did not work on a buffer size of 1 even if the other inputs were valid --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401511 --- core/sm_stringutil.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index a76268c4..9181b628 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -1037,11 +1037,30 @@ char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t se size_t textLen = strlen(subject); /* It's not possible to search or replace */ - if (searchLen > textLen || maxLen <= 1) + if (searchLen > textLen) { return NULL; } + /* Handle the case of one byte replacement. + * It's only valid in one case. + */ + if (maxLen == 1) + { + /* If the search matches and the replace length is 0, + * we can just terminate the string and be done. + */ + if (strcmp(subject, search) == 0 && replaceLen == 0) + { + *subject = '\0'; + return subject; + } + else + { + return NULL; + } + } + /* Subtract one off the maxlength so we can include the null terminator */ maxLen--;