fixing potential NULL dereference in reading GGUF file

This commit is contained in:
tpltnt 2023-10-10 18:27:00 +02:00
parent 94496cd49c
commit 7e60415bc9

View file

@ -92,7 +92,10 @@ static bool gguf_ex_read_0(const std::string & fname) {
};
struct gguf_context * ctx = gguf_init_from_file(fname.c_str(), params);
if (NULL == ctx) {
fprintf(stderr, "could not retrieve GGUF data context from file.\n");
exit(1);
}
printf("%s: version: %d\n", __func__, gguf_get_version(ctx));
printf("%s: alignment: %zu\n", __func__, gguf_get_alignment(ctx));
printf("%s: data offset: %zu\n", __func__, gguf_get_data_offset(ctx));
@ -152,7 +155,10 @@ static bool gguf_ex_read_1(const std::string & fname) {
};
struct gguf_context * ctx = gguf_init_from_file(fname.c_str(), params);
if (NULL == ctx) {
fprintf(stderr, "could not retrieve GGUF data context from file.\n");
exit(1);
}
printf("%s: version: %d\n", __func__, gguf_get_version(ctx));
printf("%s: alignment: %zu\n", __func__, gguf_get_alignment(ctx));
printf("%s: data offset: %zu\n", __func__, gguf_get_data_offset(ctx));