Skip to content

Commit d9f2fe1

Browse files
committed
Check for malloc failure
1 parent 7271ae6 commit d9f2fe1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tagger/src/tagger.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" char* DST = NULL; // alias for BUF
2727

2828
namespace compsky {
2929
namespace asciify {
30-
char* BUF = (char*)malloc(4096 * 1024);
30+
char* BUF;
3131
constexpr const size_t BUF_SZ = 4096 * 1024;
3232
}
3333
}
@@ -42,6 +42,9 @@ constexpr size_t strlen_constexpr(const char* s){
4242
}
4343

4444

45+
46+
47+
4548
size_t id2str(uint64_t id_orig, char* buf){
4649
size_t n_digits = 0;
4750
uint64_t id = id_orig;
@@ -78,6 +81,9 @@ constexpr uint64_t str2id(const char* str, const size_t start_index, const siz
7881
extern "C"
7982
void init(){
8083
compsky::mysql::init(getenv("RSCRAPER_MYSQL_CFG"));
84+
compsky::asciify::BUF = (char*)malloc(compsky::asciify::BUF_SZ);
85+
if (compsky::asciify::BUF == nullptr)
86+
abort();
8187
}
8288

8389
extern "C"

0 commit comments

Comments
 (0)