aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-12-16 16:49:06 +0100
committerJan200101 <sentrycraft123@gmail.com>2021-03-26 18:53:25 +0100
commit4cdda939de174c8fa8c6e701b3b8acd7309e6358 (patch)
treea0dbac44c23a1857603c9f6456c8e5425f9238a7 /src
parenta94b0e36ad9383f40351582689ffdfdd96720f23 (diff)
downloadpolecat-4cdda939de174c8fa8c6e701b3b8acd7309e6358.tar.gz
polecat-4cdda939de174c8fa8c6e701b3b8acd7309e6358.zip
ensure variable key is fully compared, return head to offset […]
- comparing only the first X characters can result inaccurate results - we cannot return head to the start of the string because that would mean it can reparse variables that call a function
Diffstat (limited to 'src')
-rw-r--r--src/lutris.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lutris.c b/src/lutris.c
index df5feef..ca48391 100644
--- a/src/lutris.c
+++ b/src/lutris.c
@@ -30,7 +30,7 @@ COMMAND(lutris, debug)
char* str = malloc(255);
- strcpy(str, "$string and $func $fun");
+ strcpy(str, "$string $str $func $fun");
printf("Input: %s\n", str);
parseVar(&str, variables, ARRAY_LEN(variables));
@@ -555,6 +555,7 @@ size_t parseVar(char** pvar, struct list_t* variables, size_t variable_count)
char* buf, *key;
size_t varcount = 0;
+ size_t offset = 0;
while (*head != '\0')
{
@@ -566,6 +567,8 @@ size_t parseVar(char** pvar, struct list_t* variables, size_t variable_count)
end = strlen(var) + var;
+ offset = head - var;
+
int bufend = (head-var);
// find variable key
@@ -583,7 +586,7 @@ size_t parseVar(char** pvar, struct list_t* variables, size_t variable_count)
strncpy(buf, head, tail-head);
for (size_t i = 0; i < variable_count; ++i)
{
- if (strncmp(variables[i].key, buf, tail-head) == 0)
+ if (strncmp(variables[i].key, buf, tail-head+1) == 0)
{
switch (variables[i].type)
{
@@ -625,7 +628,7 @@ size_t parseVar(char** pvar, struct list_t* variables, size_t variable_count)
varcount++;
// bring your head back to the world of living memory
- head = var;
+ head = var + offset;
}
head++;