libutil

C Utility Library
git clone http://git.omkov.net/libutil
Log | Tree | Refs | README | LICENCE | Download

AuthorJamozed <[email protected]>
Date2020-11-12 11:03:34
Commit8b7b0e190f527e397560be8e6a0671a59cd01cd5
Parentbc682d2c8c0740e739a517a99083628608806d21

mode: Allocate memory for null in chmod_t array

Diffstat

M src/lib/mode.c | 4 ++--
M src/lib/mode.h | 2 +-

2 files changed, 3 insertions, 3 deletions

diff --git a/src/lib/mode.c b/src/lib/mode.c
index 7388077..5714c8f 100644
--- a/src/lib/mode.c
+++ b/src/lib/mode.c
@@ -1,4 +1,4 @@
-// mode.c, version 1.0.0
+// mode.c, version 1.0.1
 // Mode source file for OMKOV lib
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -69,7 +69,7 @@ chmod_t *strmode(char *str) {
 
 	// Allocate necesary memory for chmod_t array
 	for (i = 1; *s; ++s) { i += (*s == '+' || *s == '-' || *s == '='); }
-	m = (chmod_t *)malloc(i * sizeof (*m)); s = str; m[i].flag = MF_NULL;
+	m = (chmod_t *)malloc((i + 1) * sizeof (*m)); s = str; m[i].flag = MF_NULL;
 
 	i = 0; do { // Parse each part of the symbolic mode string
 		for (mode_t ref = getref(&s); ((m[i].op = getop(&s))); ++i) {
diff --git a/src/lib/mode.h b/src/lib/mode.h
index ec2f45a..407dcd4 100644
--- a/src/lib/mode.h
+++ b/src/lib/mode.h
@@ -1,4 +1,4 @@
-// mode.h, version 1.0.0
+// mode.h, version 1.0.1
 // Mode header file for OMKOV lib
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.