Skip to content
Permalink
Browse files

Lint cleanup

These cppcheck warnings are false positives:

[src/lib/libast/regex/regcache.c:126] warning (objectIndex):
 The address of local variable 'key' might be accessed at non-zero index.
[src/lib/libast/regex/regcache.c:127] warning (objectIndex):
 The address of local variable 'key' might be accessed at non-zero index.

Nonetheless, modify the code to make it clearer and as a byproduct
eliminate those warnings.
  • Loading branch information
krader1961 committed Dec 1, 2019
1 parent 2806b21 commit 5c16e8d3d793f6bde42c890d2692a76b35a49959
Showing with 9 additions and 8 deletions.
  1. +9 −8 src/lib/libast/regex/regcache.c
@@ -26,6 +26,7 @@
#include "config_ast.h" // IWYU pragma: keep

#include <locale.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

@@ -35,7 +36,10 @@
#define CACHE 8 /* default # cached re's */
#define ROUND 64 /* pattern buffer size round */

typedef unsigned long Key_t;
typedef union {
char chr[4];
uint32_t uint;
} Key_t;

typedef struct Cache_s {
char *pattern;
@@ -119,20 +123,17 @@ regex_t *regcache(const char *pattern, regflags_t reflags, int *status) {
regex_flushcache();
}

/*
* check if the pattern is in the cache
*/

for (i = 0; i < sizeof(key) && pattern[i]; i++) ((char *)&key)[i] = pattern[i];
for (; i < sizeof(key); i++) ((char *)&key)[i] = 0;
// Check if the pattern is in the cache.
key.uint = 0;
for (i = 0; i < sizeof(key) && pattern[i]; i++) key.chr[i] = pattern[i];
empty = unused = -1;
old = 0;
for (i = matchstate.size; i--;) {
if (!matchstate.cache[i]) {
empty = i;
} else if (!matchstate.cache[i]->keep) {
unused = i;
} else if (*(Key_t *)matchstate.cache[i]->pattern == key &&
} else if (((Key_t *)matchstate.cache[i]->pattern)->uint == key.uint &&
!strcmp(matchstate.cache[i]->pattern, pattern) &&
matchstate.cache[i]->reflags == reflags) {
break;

0 comments on commit 5c16e8d

Please sign in to comment.
You can’t perform that action at this time.