aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-08-26 06:25:57 +0000
committerEric Wong <normalperson@yhbt.net>2006-08-26 06:25:57 +0000
commit90847fc8818836a296e9d500725c0eb154a4d3c5 (patch)
tree2c1f9d1c294749045c4462ad43baeee1a5aee815 /src/playlist.c
parentbe554c2596c8d7f905e25a67b60f4497c76d4d9f (diff)
downloadmpd-90847fc8818836a296e9d500725c0eb154a4d3c5.tar.gz
mpd-90847fc8818836a296e9d500725c0eb154a4d3c5.tar.xz
mpd-90847fc8818836a296e9d500725c0eb154a4d3c5.zip
Replace strdup and {c,re,m}alloc with x* variants to check for OOM errors
I'm checking for zero-size allocations and assert()-ing them, so we can more easily get backtraces and debug problems, but we'll also allow -DNDEBUG people to live on the edge if they wish. We do not rely on errno when checking for OOM errors because some implementations of malloc do not set it, and malloc is commonly overridden by userspace wrappers. I've spent some time looking through the source and didn't find any obvious places where we would explicitly allocate 0 bytes, so we shouldn't trip any of those assertions. We also avoid allocating zero bytes because C libraries don't handle this consistently (some return NULL, some not); and it's dangerous either way. git-svn-id: https://svn.musicpd.org/mpd/trunk@4690 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/playlist.c')
-rw-r--r--src/playlist.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/playlist.c b/src/playlist.c
index 8671e6596..c977d0e4f 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -161,12 +161,12 @@ void initPlaylist(void)
if (playlist_saveAbsolutePaths == -1) playlist_saveAbsolutePaths = 0;
else if (playlist_saveAbsolutePaths < 0) exit(EXIT_FAILURE);
- playlist.songs = malloc(sizeof(Song *) * playlist_max_length);
- playlist.songMod = malloc(sizeof(mpd_uint32) * playlist_max_length);
- playlist.order = malloc(sizeof(int) * playlist_max_length);
- playlist.idToPosition = malloc(sizeof(int) * playlist_max_length *
+ playlist.songs = xmalloc(sizeof(Song *) * playlist_max_length);
+ playlist.songMod = xmalloc(sizeof(mpd_uint32) * playlist_max_length);
+ playlist.order = xmalloc(sizeof(int) * playlist_max_length);
+ playlist.idToPosition = xmalloc(sizeof(int) * playlist_max_length *
PLAYLIST_HASH_MULT);
- playlist.positionToId = malloc(sizeof(int) * playlist_max_length);
+ playlist.positionToId = xmalloc(sizeof(int) * playlist_max_length);
memset(playlist.songs, 0, sizeof(char *) * playlist_max_length);
@@ -1264,7 +1264,7 @@ int shufflePlaylist(int fd)
int deletePlaylist(int fd, char *utf8file)
{
char *file = utf8ToFsCharset(utf8file);
- char *rfile = malloc(strlen(file) + strlen(".") +
+ char *rfile = xmalloc(strlen(file) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
char *actualFile;
@@ -1308,7 +1308,7 @@ int savePlaylist(int fd, char *utf8file)
file = utf8ToFsCharset(utf8file);
- rfile = malloc(strlen(file) + strlen(".") +
+ rfile = xmalloc(strlen(file) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
strcpy(rfile, file);
@@ -1421,7 +1421,7 @@ static int PlaylistIterFunc(int fd, char *utf8file,
char s[MAXPATHLEN + 1];
int slength = 0;
char *temp = utf8ToFsCharset(utf8file);
- char *rfile = malloc(strlen(temp) + strlen(".") +
+ char *rfile = xmalloc(strlen(temp) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
char *actualFile;
char *parent = parentPath(temp);
@@ -1461,7 +1461,7 @@ static int PlaylistIterFunc(int fd, char *utf8file,
if (strncmp(s, musicDir, strlen(musicDir)) == 0) {
strcpy(s, &(s[strlen(musicDir)]));
} else if (parentlen) {
- temp = strdup(s);
+ temp = xstrdup(s);
memset(s, 0, MAXPATHLEN + 1);
strcpy(s, parent);
strncat(s, "/", MAXPATHLEN - parentlen);
@@ -1536,7 +1536,7 @@ static void PlaylistLoadIterFunc(int fd, char *temp, char **erroredFile)
} else if ((addToPlaylist(STDERR_FILENO, temp, 0)) < 0) {
/* for windows compatibilit, convert slashes */
- char *temp2 = strdup(temp);
+ char *temp2 = xstrdup(temp);
char *p = temp2;
while (*p) {
if (*p == '\\')
@@ -1545,7 +1545,7 @@ static void PlaylistLoadIterFunc(int fd, char *temp, char **erroredFile)
}
if ((addToPlaylist(STDERR_FILENO, temp2, 0)) < 0) {
if (!*erroredFile) {
- *erroredFile = strdup(temp);
+ *erroredFile = xstrdup(temp);
}
}
free(temp2);