Skip to content

Commit ff5c73a

Browse files
committed
More nob fixes
1 parent a7f863e commit ff5c73a

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

nob.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ void build_object(Nob_Cmd *cmd, LibFlagsDa *main_flags,
6767
char *run_cmd_and_get_output(Nob_Cmd *cmd, char *tmp_filename) {
6868
char template[] = "/tmp/tmpdir.wpc-nob-XXXXXX";
6969
char *dir_name = mkdtemp(template);
70+
if (dir_name == NULL) {
71+
nob_log(NOB_ERROR, "mkdtemp failed: %s", strerror(errno));
72+
return NULL;
73+
}
7074
char *file_path = nob_temp_sprintf("%s/%s.txt", dir_name, tmp_filename);
7175
Nob_String_Builder builder = {0};
7276

@@ -75,7 +79,11 @@ char *run_cmd_and_get_output(Nob_Cmd *cmd, char *tmp_filename) {
7579
nob_read_entire_file(file_path, &builder);
7680
if (builder.count == 0 || builder.items == NULL) {
7781
nob_da_free(builder);
82+
unlink(file_path);
83+
rmdir(dir_name);
84+
return NULL;
7885
}
86+
nob_da_append(&builder, '\0');
7987
char *output = strdup(builder.items);
8088
unlink(file_path);
8189
rmdir(dir_name);
@@ -100,16 +108,15 @@ LibFlagsDa list_lib_flags(Nob_Cmd *cmd, char *lib_names[], bool cflags) {
100108
}
101109

102110
char *buffer = run_cmd_and_get_output(cmd, name);
103-
111+
if (buffer == NULL) {
112+
exit(1);
113+
}
104114
LibFlagsDa lib_places = {0};
105-
char *lib = strtok(buffer, " ");
106-
nob_da_append(&lib_places, strdup(lib));
107-
while ((lib = strtok(NULL, " ")) != NULL) {
108-
if (isspace(lib[0])) {
109-
continue;
110-
}
115+
const char *delims = " \t\r\n";
116+
char *lib = strtok(buffer, delims);
117+
while (lib != NULL) {
111118
nob_da_append(&lib_places, strdup(lib));
112-
lib += strlen(lib) + 1;
119+
lib = strtok(NULL, delims);
113120
}
114121
free(name);
115122
free(buffer);
@@ -255,6 +262,10 @@ void should_use_imagemagick7(Nob_Cmd *cmd) {
255262
nob_cmd_append(cmd, "pkg-config", "--modversion", "MagickWand");
256263

257264
char *buffer = run_cmd_and_get_output(cmd, "imagemagick");
265+
if (buffer == NULL) {
266+
nob_log(NOB_ERROR, "Could not read pkg-config --modversion output.");
267+
exit(1);
268+
}
258269

259270
if (strncmp(buffer, "7.", 2) == 0) {
260271
use_imagemagick7 = true;
@@ -280,9 +291,11 @@ void setup_lightdm_helper_flags(void) {
280291
char *helper_path_var = getenv("WPC_HELPER_PATH");
281292

282293
if (helper_path_var != NULL) {
283-
strcpy(lightdm_helper_path, helper_path_var);
294+
snprintf(lightdm_helper_path, sizeof(lightdm_helper_path), "%s",
295+
helper_path_var);
284296
} else {
285-
strcpy(lightdm_helper_path, "/usr/local/libexec/wpc/lightdm_helper");
297+
snprintf(lightdm_helper_path, sizeof(lightdm_helper_path), "%s",
298+
"/usr/local/libexec/wpc/lightdm_helper");
286299
}
287300

288301
// set enable_lightdm_helper to true if enable_helper_var is not equal

0 commit comments

Comments
 (0)