Skip to content

Commit b193d53

Browse files
authored
ggml : do not output unprintable characters on GGUF load failure (#14381)
1 parent 2bf9d53 commit b193d53

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ggml/src/gguf.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
335335

336336
for (uint32_t i = 0; i < magic.size(); i++) {
337337
if (magic[i] != GGUF_MAGIC[i]) {
338-
GGML_LOG_ERROR("%s: invalid magic characters: '%c%c%c%c', expected 'GGUF'\n", __func__, magic[0], magic[1], magic[2], magic[3]);
338+
char c0 = isprint(magic[0]) ? magic[0] : '?';
339+
char c1 = isprint(magic[1]) ? magic[1] : '?';
340+
char c2 = isprint(magic[2]) ? magic[2] : '?';
341+
char c3 = isprint(magic[3]) ? magic[3] : '?';
342+
GGML_LOG_ERROR("%s: invalid magic characters: '%c%c%c%c', expected 'GGUF'\n", __func__, c0, c1, c2, c3);
339343
gguf_free(ctx);
340344
return nullptr;
341345
}

0 commit comments

Comments
 (0)