aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-02-25 13:04:04 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-02-25 13:04:04 -0500
commitb445434992254b2f531fe7385b7d05c7353b66ad (patch)
treeac347ec91007cfdad00b992a1d64066bfc710431 /src
parent02793ccec496e9ca1ea5e3474b70b39dfea388a9 (diff)
downloadspmc-b445434992254b2f531fe7385b7d05c7353b66ad.tar.gz
Fix invalid array access on short strings
Diffstat (limited to 'src')
-rw-r--r--src/str.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/str.c b/src/str.c
index dbf0c42..605bbee 100644
--- a/src/str.c
+++ b/src/str.c
@@ -453,12 +453,18 @@ char *lstrip(char *sptr) {
* @return truncated string
*/
char *strip(char *sptr) {
- size_t len = strlen(sptr) - 1;
- if (len < 1 && isblank(*sptr)) {
+ size_t len = strlen(sptr);
+ if (len == 0) {
+ return sptr;
+ }
+ else if (len == 1) {
*sptr = '\0';
return sptr;
}
- for (size_t i = len; ; i--) {
+ for (size_t i = len; i != 0; --i) {
+ if (sptr[i] == '\0') {
+ continue;
+ }
if (isspace(sptr[i]) || isblank(sptr[i])) {
sptr[i] = '\0';
}