diff options
author | mbkma <[email protected]> | 2025-08-14 17:07:17 +0200 |
---|---|---|
committer | mbkma <[email protected]> | 2025-08-14 17:07:17 +0200 |
commit | 420dcec34bbc9b20bd79f2dc84c1a810c06dbb84 (patch) | |
tree | 5372d3ff59cf6422483c8a3ce8b2e4eb33553a62 | |
parent | 7ef327f6f269c7a49357e001cd41d7aaf5807749 (diff) | |
download | mate-calc-fix/malloc.tar.bz2 mate-calc-fix/malloc.tar.xz |
add missing byte in malloc for null terminatorfix/malloc
-rw-r--r-- | src/parser.c | 2 | ||||
-rw-r--r-- | src/parserfunc.c | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c index d60c142..c9d711b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -343,7 +343,7 @@ p_check_variable(ParserState* state, gchar* name) if(utf8_next_char(name)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(name)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(name) + 1)); for(c = name; *c != '\0'; c = next) { next = utf8_next_char(c); diff --git a/src/parserfunc.c b/src/parserfunc.c index dc28e7e..1d45467 100644 --- a/src/parserfunc.c +++ b/src/parserfunc.c @@ -191,7 +191,7 @@ pf_get_variable(ParseNode* self) if(utf8_next_char(self->token->string)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + 1)); mp_set_from_integer(1, &value); for(c = self->token->string; *c != '\0'; c = next) { @@ -252,7 +252,7 @@ pf_get_variable_with_power(ParseNode* self) if(utf8_next_char(self->token->string)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + 1)); mp_set_from_integer(1, &value); for(c = self->token->string; *c != '\0'; c = next) { @@ -362,7 +362,7 @@ pf_apply_func_with_npower(ParseNode* self) MPNumber* ans = mp_new_ptr(); gint pow; gchar* inv_name; - inv_name = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string) + strlen("⁻¹") + 1); + inv_name = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + strlen("⁻¹") + 1)); strcpy(inv_name, self->token->string); strcat(inv_name, "⁻¹"); val = (MPNumber*) (*(self->right->evaluate))(self->right); |