1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-13 18:26:45 +02:00

Do proper error handling for a few malloc calls

This commit is contained in:
jfreegman
2021-12-12 11:30:27 -05:00
parent 3eac65036c
commit bf1e1b73fc
3 changed files with 26 additions and 3 deletions

View File

@ -489,16 +489,27 @@ void terminate_notify(void)
}
#ifdef SOUND_NOTIFY
int set_sound(Notification sound, const char *value)
/*
* Sets notification sound designated by `sound` to file path `value`.
*
* Return true if the sound is successfully set.
*/
bool set_sound(Notification sound, const char *value)
{
if (sound == silent) {
return 0;
return false;
}
free(Control.sounds[sound]);
size_t len = strlen(value) + 1;
Control.sounds[sound] = calloc(len, 1);
if (Control.sounds[sound] == NULL) {
return false;
}
memcpy(Control.sounds[sound], value, len);
struct stat buf;