Skip to content

Commit ceb1329

Browse files
committed
make all print statements consistent and secure
1 parent d38661b commit ceb1329

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

shared/audio.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int audio_init(void) {
6262
int driver_found = 0;
6363
for (int i = 0; i < sizeof(drivers) / sizeof(drivers[0]); i++) {
6464
if (SDL_AudioInit(drivers[i]) == 0) {
65-
fprintf(stdout, "Audio driver: %s\n", drivers[i]);
65+
printf("Audio driver: %s\n", drivers[i]);
6666
char msg[256];
6767
snprintf(msg, sizeof(msg), "Audio driver: %s", drivers[i]);
6868
notify_show(NOTIFY_SUCCESS, msg);
@@ -71,18 +71,18 @@ int audio_init(void) {
7171
}
7272
}
7373
if (!driver_found) {
74-
fprintf(stderr, "Could not initialize any audio driver, continuing without sound.\n");
74+
printf("Could not initialize any audio driver, continuing without sound.\n");
7575
notify_show(NOTIFY_ERROR, "Could not initialize audio driver");
7676
notify_show(NOTIFY_INFO, "Continuing without sound");
7777
}
7878
audio.device = SDL_OpenAudioDevice(NULL, 0, &audio.audiospec, NULL, SDL_AUDIO_ALLOW_ANY_CHANGE);
7979
if (!audio.device) {
80-
fprintf(stderr, "No audio device available, using dummy driver. %s\n", SDL_GetError());
80+
printf("No audio device available, using dummy driver. %s\n", SDL_GetError());
8181
notify_show(NOTIFY_INFO, "Using dummy audio driver");
8282
SDL_setenv("SDL_AUDIODRIVER", "dummy", 1);
8383
audio.device = SDL_OpenAudioDevice(NULL, 0, &audio.audiospec, NULL, SDL_AUDIO_ALLOW_ANY_CHANGE);
8484
if (!audio.device) {
85-
fprintf(stderr, "Failed to initialize audio (even with dummy driver): %s\n", SDL_GetError());
85+
printf("Failed to initialize audio (even with dummy driver): %s\n", SDL_GetError());
8686
notify_show(NOTIFY_ERROR, "Failed to initialize audio");
8787
return 1;
8888
}

shared/chip8.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int chip8_init(
4141
SDL_INIT_VIDEO |
4242
SDL_INIT_EVENTS
4343
)) {
44-
fprintf(stderr,"Error: %s\n", SDL_GetError());
44+
printf("Error: %s\n", SDL_GetError());
4545
return 1;
4646
}
4747

@@ -53,14 +53,14 @@ int chip8_init(
5353
chip8.vram = (unsigned char **) malloc(WIDTH * sizeof(unsigned char *));
5454
const char *err_str = "Unable to allocate memory on the heap.\n";
5555
if (!chip8.vram) {
56-
fprintf(stderr, "%s", err_str);
56+
printf("%s", err_str);
5757
return 1;
5858
}
5959
memset(chip8.vram, 0, WIDTH * sizeof(unsigned char *));
6060
for (int i = 0; i < WIDTH; i++) {
6161
chip8.vram[i] = (unsigned char *) malloc(HEIGHT * sizeof(unsigned char));
6262
if (!chip8.vram[i]) {
63-
fprintf(stderr, "%s", err_str);
63+
printf("%s", err_str);
6464
return 1;
6565
}
6666
memset(chip8.vram[i], 0, HEIGHT * sizeof(unsigned char));
@@ -103,7 +103,7 @@ int chip8_load_bootrom() {
103103
chip8.rom_size = BOOTROM_SIZE;
104104
chip8.rom = (unsigned char *)malloc(chip8.rom_size);
105105
if(!chip8.rom) {
106-
fprintf(stderr, "Unable to allocate memory for rom.\n");
106+
printf("Unable to allocate memory for rom.\n");
107107
return 1;
108108
}
109109
memset(chip8.rom, 0 , chip8.rom_size);
@@ -191,7 +191,7 @@ int chip8_load_rom(const char *rom_filepath) {
191191
/* load ROM from GUI */
192192
char new_rom_name[PATH_MAX];
193193
openFileDialog(new_rom_name) ?
194-
fprintf(stdout, "User aborted the open file dialog.\n") :
194+
printf("User aborted the open file dialog.\n") :
195195
chip8_load_rom(new_rom_name);
196196

197197
/* flip GUI toggle */

shared/display.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ int display_init(bool fullscreen) {
4848
const char *err_str = "Unable to allocate memory on the heap.\n";
4949

5050
if(!display.back_buffer) {
51-
fprintf(stderr, "%s", err_str);
51+
printf("%s", err_str);
5252
return 1;
5353
}
5454
memset(display.back_buffer, 0, WIDTH * sizeof(unsigned char *));
5555

5656
for (int i = 0; i < WIDTH; i++) {
5757
display.back_buffer[i] = (unsigned char *) malloc(HEIGHT * sizeof(unsigned char));
5858
if(!display.back_buffer[i]) {
59-
fprintf(stderr, "%s", err_str);
59+
printf("%s", err_str);
6060
return 1;
6161
}
6262
memset(display.back_buffer[i], 0, HEIGHT * sizeof(unsigned char));
@@ -79,7 +79,7 @@ int display_init(bool fullscreen) {
7979
);
8080

8181
if (display.window == NULL) {
82-
fprintf(stderr, "Error: %s\n", SDL_GetError());
82+
printf("Error: %s\n", SDL_GetError());
8383
return 1;
8484
}
8585

shared/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main(int argc, char **argv){
3131
}
3232
}
3333
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
34-
fprintf(stderr, "%s", USAGE_TEXT);
34+
printf("%s", USAGE_TEXT);
3535
return 0;
3636
}
3737
if (strcmp(argv[i], "--fullscreen") == 0) fullscreen = 1;

shared/profiles.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void profiles_load_from_file(void) {
4646
char notif_msg[256];
4747
snprintf(notif_msg, sizeof(notif_msg), "Failed to create: %s", loaded_profiles_path);
4848
notify_show(NOTIFY_ERROR, notif_msg);
49-
fprintf(stderr, "Error: Unable to create profiles.ini at: %s\n", loaded_profiles_path);
49+
printf("Error: Unable to create profiles.ini at: %s\n", loaded_profiles_path);
5050
}
5151
return;
5252
}
@@ -57,7 +57,7 @@ static void profiles_load_from_file(void) {
5757
/* Get executable's base path using SDL */
5858
base_path = SDL_GetBasePath();
5959
if (!base_path) {
60-
fprintf(stderr, "Warning: Could not determine executable path. Trying current directory.\n");
60+
printf("Warning: Could not determine executable path. Trying current directory.\n");
6161
snprintf(search_paths[0], sizeof(search_paths[0]), "./profiles.ini");
6262
snprintf(search_paths[1], sizeof(search_paths[1]), "../Resources/profiles.ini");
6363
} else {
@@ -99,7 +99,7 @@ static void profiles_load_from_file(void) {
9999
notify_show(NOTIFY_INFO, notif_msg);
100100
} else {
101101
notify_show(NOTIFY_ERROR, "Failed to create profiles.ini");
102-
fprintf(stderr, "Error: Unable to create profiles.ini at: %s\n", search_paths[0]);
102+
printf("Error: Unable to create profiles.ini at: %s\n", search_paths[0]);
103103
}
104104
return;
105105
}
@@ -132,7 +132,7 @@ static void profiles_load_from_file(void) {
132132
}
133133

134134
if (sscanf(line, "[0x%x]", &current_crc) != 1) {
135-
fprintf(stderr, "Error: Invalid profile section header: %s\n", line);
135+
printf("Error: Invalid profile section header: %s\n", line);
136136
current_crc = 0;
137137
continue;
138138
}
@@ -215,13 +215,13 @@ static void profiles_write_to_file(void) {
215215
int i;
216216

217217
if (loaded_profiles_path[0] == '\0') {
218-
fprintf(stderr, "Error: profiles.ini path not initialized\n");
218+
printf("Error: profiles.ini path not initialized\n");
219219
return;
220220
}
221221

222222
file = fopen(loaded_profiles_path, "w");
223223
if (!file) {
224-
fprintf(stderr, "Error: Unable to write to %s\n", loaded_profiles_path);
224+
printf("Error: Unable to write to %s\n", loaded_profiles_path);
225225
return;
226226
}
227227

@@ -284,7 +284,7 @@ void profiles_save_current(void) {
284284
/* Write entire hashmap to INI file */
285285
profiles_write_to_file();
286286

287-
fprintf(stdout, "Saved ROM profile for: %s (CRC32: 0x%X)\n",
287+
printf("Saved ROM profile for: %s (CRC32: 0x%X)\n",
288288
chip8.rom_filename, crc32);
289289

290290
/* Show success notification with path */

0 commit comments

Comments
 (0)