/*
- * Copyright (C) 2015-2019 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
* Author "Fulup Ar Foll"
* Author: José Bollo <jose.bollo@iot.bzh>
*
/* search the token */
tok = tokenset.first;
- while (tok && memcmp(tokenstring, tok->text, length))
+ while (tok && (memcmp(tokenstring, tok->text, length) || tokenstring[length]))
tok = tok->next;
/* search done */
rc = 0;
} else {
/* not found, create */
- tok = malloc(length + sizeof *tok);
+ tok = malloc(length + 1 + sizeof *tok);
if (!tok)
/* creation failed */
rc = -ENOMEM;
tokenset.first = tok;
tok->id = tokenset.idgen;
tok->refcount = 1;
- memcpy(tok->text, tokenstring, length);
+ memcpy(tok->text, tokenstring, length + 1);
rc = 0;
}
}
pthread_mutex_lock(&tokenset.mutex);
pt = &tokenset.first;
while (*pt && *pt != token)
+ pt = &(*pt)->next;
if (*pt)
*pt = token->next;
pthread_mutex_unlock(&tokenset.mutex);