mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-09 20:24:14 +00:00
[egl] shader: fix reliance on null terminated strings
Compiled in resources often will not contain a null terminator, as such we must not use functions that rely on it. This implements a memsearch function that performs like strstr on a buffer instead of a null terminated string.
This commit is contained in:
@@ -37,4 +37,10 @@ bool str_containsValue(const char * list, char delimiter, const char * value);
|
||||
// Local implementation of strdup
|
||||
char * lg_strdup(const char *s);
|
||||
|
||||
// search a non null terminated buffer for a value
|
||||
const char * memsearch(
|
||||
const char * haystack, size_t haystackSize,
|
||||
const char * needle , size_t needleSize ,
|
||||
const char * offset);
|
||||
|
||||
#endif
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "common/stringutils.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
int valloc_sprintf(char ** str, const char * format, va_list ap)
|
||||
{
|
||||
@@ -110,3 +111,24 @@ char * lg_strdup(const char *s)
|
||||
memcpy(out, s, len);
|
||||
return out;
|
||||
}
|
||||
|
||||
const char * memsearch(
|
||||
const char * haystack, size_t haystackSize,
|
||||
const char * needle , size_t needleSize ,
|
||||
const char * offset)
|
||||
{
|
||||
int i = 0;
|
||||
if (offset)
|
||||
{
|
||||
DEBUG_ASSERT(offset >= haystack);
|
||||
DEBUG_ASSERT(offset < haystack + haystackSize);
|
||||
i = offset - haystack;
|
||||
}
|
||||
|
||||
const int searchSize = haystackSize - needleSize + 1;
|
||||
for(; i < searchSize; ++i)
|
||||
if (memcmp(haystack + i, needle, needleSize) == 0)
|
||||
return haystack + i;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user