Skip to content

Commit

Permalink
libks: sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mptre committed Jun 30, 2024
1 parent 7c8ed88 commit 59e41e8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cpp-include.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ is_main_include(const char *include_path, const char *path,
arena_scope(scratch, s);

/* Transform path "a/b.c" into "a/b.h". */
str = VECTOR_FIRST(KS_str_split(path, '.', &s));
str = VECTOR_FIRST(KS_str_split(path, ".", &s));
if (str == NULL)
return 0; /* UNREACHABLE */
basename = *str;
Expand All @@ -201,11 +201,11 @@ is_main_include(const char *include_path, const char *path,
return 1;

/* Transform path "a/b.c" into "b.h". */
str = VECTOR_LAST(KS_str_split(path, '/', &s));
str = VECTOR_LAST(KS_str_split(path, "/", &s));
if (str == NULL)
return 0; /* UNREACHABLE */
filename = *str;
str = VECTOR_FIRST(KS_str_split(filename, '.', &s));
str = VECTOR_FIRST(KS_str_split(filename, ".", &s));
if (str == NULL)
return 0; /* UNREACHABLE */
basename = *str;
Expand Down
3 changes: 2 additions & 1 deletion fuzz-style.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "config.h"

#include "libks/arena.h"
#include "libks/compiler.h"
#include "libks/fuzzer.h"

#include "options.h"
Expand All @@ -13,7 +14,7 @@ struct test_context {
};

static void *
init(void)
init(int UNUSED(argc), char **UNUSED(argv))
{
static struct test_context c;

Expand Down
15 changes: 7 additions & 8 deletions libks/fuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <stdint.h>

#include "libks/buffer.h"
#include "libks/compiler.h"
#include "libks/tmp.h"

#if !defined(FUZZER_AFL) && !defined(FUZZER_LLVM)
Expand All @@ -43,7 +42,7 @@ struct fuzzer_target {
};

union fuzzer_callback {
void *(*init)(void);
void *(*init)(int, char **);
void (*teardown)(void *);
};

Expand Down Expand Up @@ -85,7 +84,7 @@ FUZZER_SECTION(teardown);

__attribute__((NO_SANITIZE_UNDEFINED))
static inline void *
fuzzer_init(void)
fuzzer_init(int argc, char *argv[])
{
/* NOLINTBEGIN(bugprone-reserved-identifier) */

Expand All @@ -95,7 +94,7 @@ fuzzer_init(void)

for (; it != &__stop_fuzzer_callback_init; it++) {
if (it->init != NULL)
return it->init();
return it->init(argc, argv);
}
return NULL;

Expand Down Expand Up @@ -123,11 +122,11 @@ fuzzer_teardown(void *userdata)
#if defined(FUZZER_AFL)

int
main(void)
main(int argc, char *argv[])
{
void *userdata;

userdata = fuzzer_init();
userdata = fuzzer_init(argc, argv);

if (fuzzer_target.buffer) {
struct buffer *bf;
Expand Down Expand Up @@ -187,9 +186,9 @@ LLVMFuzzerTestOneInput(const uint8_t *buf, size_t buflen)
}

int
LLVMFuzzerInitialize(int *UNUSED(argc), char ***UNUSED(argv))
LLVMFuzzerInitialize(int *argc, char ***argv)
{
fuzzer_llvm_userdata = fuzzer_init();
fuzzer_llvm_userdata = fuzzer_init(*argc, *argv);

return 0;
}
Expand Down
8 changes: 5 additions & 3 deletions libks/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,13 @@ KS_str_match_native(const char *USED_IF_X86_64(str), size_t USED_IF_X86_64(len),
#endif

char **
KS_str_split(const char *str, char delim, struct arena_scope *s)
KS_str_split(const char *str, const char *delim, struct arena_scope *s)
{
VECTOR(char *) parts;
size_t delimlen;

ARENA_VECTOR_INIT(s, parts, 2);
delimlen = strlen(delim);

for (;;) {
const char *p;
Expand All @@ -251,10 +253,10 @@ KS_str_split(const char *str, char delim, struct arena_scope *s)
dst = VECTOR_ALLOC(parts);
if (unlikely(dst == NULL))
return NULL; /* UNREACHABLE */
p = strchr(str, delim);
p = strstr(str, delim);
if (p != NULL) {
*dst = arena_strndup(s, str, (size_t)(p - str));
str = &p[1];
str = &p[delimlen];
} else {
*dst = arena_strdup(s, str);
break;
Expand Down
2 changes: 1 addition & 1 deletion libks/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ extern unsigned int KS_features;
size_t KS_str_match_default(const char *, size_t, const char *);
size_t KS_str_match_native(const char *, size_t, const char *);

char **KS_str_split(const char *, char, struct arena_scope *);
char **KS_str_split(const char *, const char *, struct arena_scope *);

#endif /* !LIBKS_STRING_H */
2 changes: 1 addition & 1 deletion libks/tmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h> /* mkstemp(3) on Linux */
#include <unistd.h>

int
Expand Down

0 comments on commit 59e41e8

Please sign in to comment.