Last active
September 25, 2019 11:41
-
-
Save sjaeckel/103ac2e7711e2e069afc90777ce04ebb to your computer and use it in GitHub Desktop.
Valgrind vararg error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.c | |
*.o | |
*.a | |
vafail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this has been tested with gcc-4.8, clang-3.8, clang-7, clang-9 and clang-10 | |
CC=clang-7 | |
CFLAGS=-g | |
fail: all | |
${CC} -dumpversion | |
valgrind ./vafail | |
all: libvafail.a vafail | |
.c.o: | |
${CC} ${CFLAGS} -c $< -o $@ | |
libvafail.a: va_test_fun.o | |
$(AR) $(ARFLAGS) $@ $< | |
vafail: vafail.o libvafail.a | |
${CC} ${CFLAGS} $^ -o $@ | |
clean: | |
rm *.o *.a vafail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdarg.h> | |
#include <stddef.h> | |
#include <valgrind/memcheck.h> | |
void va_test_fun(int i, unsigned char *pc, unsigned long *pl, const unsigned char *p, unsigned long l, ...) | |
{ | |
va_list args; | |
const unsigned char *curptr; | |
unsigned long curlen; | |
va_start(args, l); | |
curptr = p; | |
curlen = l; | |
for (;;) { | |
VALGRIND_CHECK_VALUE_IS_DEFINED(curptr); | |
VALGRIND_CHECK_VALUE_IS_DEFINED(curlen); | |
VALGRIND_CHECK_MEM_IS_DEFINED(curptr, curlen); | |
/* step to next */ | |
curptr = va_arg(args, const unsigned char*); | |
if (curptr == NULL) { | |
break; | |
} | |
curlen = va_arg(args, unsigned long); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
void va_test_fun(int i, unsigned char *pc, unsigned long *pl, const unsigned char *p, unsigned long l, ...); | |
int main(void) | |
{ | |
unsigned long l = 123; | |
unsigned char buf[1024] = {0}; | |
va_test_fun(100, buf, &l, buf, l, buf, 4, NULL, 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment