Skip to content

Commit 55a257c

Browse files
committed
Be defensive in our indexing when un-smuggling name index
In case something goes wrong, let's just lose the ability to print the symbol name, rather than (probably) segfaulting.
1 parent d5543a9 commit 55a257c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/libblastrampoline.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,20 @@ LBT_DLLEXPORT void lbt_default_func_print_error() {
4545
// We mark as `volatile` to discourage the compiler from moving us around too much
4646
volatile uint64_t name_idx = get_forward_name_idx();
4747
const char * suffix = "";
48+
49+
// We encode `64_` by just shifting the name index up a bunch
4850
if (name_idx >= NUM_EXPORTED_FUNCS) {
4951
suffix = "64_";
5052
name_idx -= NUM_EXPORTED_FUNCS;
5153
}
52-
fprintf(stderr, "Error: no BLAS/LAPACK library loaded for %s%s()\n", exported_func_names[name_idx], suffix);
54+
55+
// If we're still off the end of our list of names, some corruption has occured,
56+
// and we should not try to index into `exported_func_names`.
57+
if (name_idx >= NUM_EXPORTED_FUNCS) {
58+
fprintf(stderr, "Error: no BLAS/LAPACK library loaded for (unknown function)\n");
59+
} else {
60+
fprintf(stderr, "Error: no BLAS/LAPACK library loaded for %s%s()\n", exported_func_names[name_idx], suffix);
61+
}
5362
}
5463
void lbt_default_func_print_error_and_exit() {
5564
lbt_default_func_print_error();

0 commit comments

Comments
 (0)