summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9de9dfc)
raw | patch | inline | side by side (parent: 9de9dfc)
author | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 23:15:20 +0000 (01:15 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 17 Sep 2008 23:15:20 +0000 (01:15 +0200) |
Fix several segmentation faults: when the connection to the MPD server
is lost, there were NULL pointer dereferences because
client->status==NULL. Check before accessing it.
is lost, there were NULL pointer dereferences because
client->status==NULL. Check before accessing it.
src/screen.c | patch | blob | history | |
src/screen_file.c | patch | blob | history | |
src/screen_play.c | patch | blob | history |
diff --git a/src/screen.c b/src/screen.c
index 14ffffe6b5828dff9bf4177ad58945bc5cd27925..beddb95b823c6cc91f617662fcaedfd4cdb9aa2f 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
waddstr(w, _(":Lyrics "));
#endif
}
- if (c->status->volume==MPD_STATUS_NO_VOLUME) {
+ if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
g_snprintf(buf, 32, _("Volume n/a "));
} else {
g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
mvwaddstr(w, 0, screen.top_window.cols-my_strlen(buf), buf);
flags[0] = 0;
- if( c->status->repeat )
- g_strlcat(flags, "r", sizeof(flags));
- if( c->status->random )
- g_strlcat(flags, "z", sizeof(flags));;
- if( c->status->crossfade )
- g_strlcat(flags, "x", sizeof(flags));
- if( c->status->updatingDb )
- g_strlcat(flags, "U", sizeof(flags));
+ if (c->status != NULL) {
+ if (c->status->repeat)
+ g_strlcat(flags, "r", sizeof(flags));
+ if (c->status->random)
+ g_strlcat(flags, "z", sizeof(flags));;
+ if (c->status->crossfade)
+ g_strlcat(flags, "x", sizeof(flags));
+ if (c->status->updatingDb)
+ g_strlcat(flags, "U", sizeof(flags));
+ }
+
colors_use(w, COLOR_LINE);
mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
if (flags[0]) {
wclrtoeol(w);
}
- if (prev_volume!=c->status->volume || full_repaint)
+ if ((c->status != NULL && prev_volume != c->status->volume) ||
+ full_repaint)
paint_top_window2(header, c);
}
{
double p;
int width;
- int elapsedTime = c->status->elapsedTime;
+ int elapsedTime;
if (c->status==NULL || IS_STOPPED(c->status->state)) {
mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
if (c->song && seek_id == c->song->id)
elapsedTime = seek_target_time;
+ else
+ elapsedTime = c->status->elapsedTime;
p = ((double) elapsedTime) / ((double) c->status->totalTime);
wclrtoeol(w);
colors_use(w, COLOR_STATUS_BOLD);
- switch(status->state) {
+ switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
case MPD_STATUS_STATE_PLAY:
str = _("Playing:");
break;
/* create time string */
memset(screen.buf, 0, screen.buf_size);
- if (IS_PLAYING(status->state) || IS_PAUSED(status->state)) {
+ if (status != NULL && (IS_PLAYING(status->state) ||
+ IS_PAUSED(status->state))) {
if (status->totalTime > 0) {
/*checks the conf to see whether to display elapsed or remaining time */
if(!strcmp(options.timedisplay_type,"elapsed"))
}
/* display song */
- if (IS_PLAYING(status->state) || IS_PAUSED(status->state)) {
+ if (status != NULL && (IS_PLAYING(status->state) ||
+ IS_PAUSED(status->state))) {
char songname[MAX_SONGNAME_LENGTH];
int width = COLS-x-my_strlen(screen.buf);
return screen_paint(c);
/* print a message if mpd status has changed */
- if (repeat < 0) {
- repeat = c->status->repeat;
- random_enabled = c->status->random;
- crossfade = c->status->crossfade;
- dbupdate = c->status->updatingDb;
- }
+ if (c->status != NULL) {
+ if (repeat < 0) {
+ repeat = c->status->repeat;
+ random_enabled = c->status->random;
+ crossfade = c->status->crossfade;
+ dbupdate = c->status->updatingDb;
+ }
- if (repeat != c->status->repeat)
- screen_status_printf(c->status->repeat ?
- _("Repeat is on") :
- _("Repeat is off"));
+ if (repeat != c->status->repeat)
+ screen_status_printf(c->status->repeat ?
+ _("Repeat is on") :
+ _("Repeat is off"));
- if (random_enabled != c->status->random)
- screen_status_printf(c->status->random ?
- _("Random is on") :
- _("Random is off"));
+ if (random_enabled != c->status->random)
+ screen_status_printf(c->status->random ?
+ _("Random is on") :
+ _("Random is off"));
- if (crossfade != c->status->crossfade)
- screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
+ if (crossfade != c->status->crossfade)
+ screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
- if (dbupdate && dbupdate != c->status->updatingDb) {
- screen_status_printf(_("Database updated!"));
- mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
- }
+ if (dbupdate && dbupdate != c->status->updatingDb) {
+ screen_status_printf(_("Database updated!"));
+ mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
+ }
- repeat = c->status->repeat;
- random_enabled = c->status->random;
- crossfade = c->status->crossfade;
- dbupdate = c->status->updatingDb;
+ repeat = c->status->repeat;
+ random_enabled = c->status->random;
+ crossfade = c->status->crossfade;
+ dbupdate = c->status->updatingDb;
+ }
/* update title/header window */
if (welcome && screen.last_cmd==CMD_NONE &&
static int
screen_client_cmd(mpdclient_t *c, command_t cmd)
{
+ if (c->connection == NULL || c->status == NULL)
+ return 0;
+
switch(cmd) {
case CMD_PLAY:
mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
diff --git a/src/screen_file.c b/src/screen_file.c
index 7465ff1255703d3f47b0a7884579f09c99e0d713..92d89232b768989ee5e1a4858544d6416311f2df 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
screen_status_printf(_("Screen updated!"));
return 1;
case CMD_DB_UPDATE:
+ if (c->status == NULL)
+ return 1;
+
if( !c->status->updatingDb )
{
if( mpdclient_cmd_db_update_utf8(c,filelist->path)==0 )
diff --git a/src/screen_play.c b/src/screen_play.c
index 75462ccf95481e7c60dd48743c5d6cbbba1e7b7f..c89d150cff17c59beeaae70eddb5ff9ae095ca84 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
song = playlist_get(&c->playlist, idx);
- if( c->song && song->id==c->song->id && !IS_STOPPED(c->status->state) ) {
+ if (c->song != NULL && song->id == c->song->id &&
+ c->status != NULL && !IS_STOPPED(c->status->state))
*highlight = 1;
- }
+
strfsong(songname, MAX_SONG_LENGTH, LIST_FORMAT, song);
return songname;
}
unsigned offset = lw->selected - lw->start;
int idx;
- if (!c->song || length<lw->rows || IS_STOPPED(c->status->state))
+ if (!c->song || length < lw->rows ||
+ c->status == NULL || IS_STOPPED(c->status->state))
return;
/* try to center the song that are playing */
play_update(screen_t *screen, mpdclient_t *c)
{
/* hide the cursor when mpd are playing and the user are inactive */
- if( options.hide_cursor>0 && c->status->state == MPD_STATUS_STATE_PLAY &&
+ if (options.hide_cursor > 0 &&
+ (c->status != NULL && c->status->state == MPD_STATUS_STATE_PLAY) &&
time(NULL)-screen->input_timestamp >= options.hide_cursor ) {
lw->flags |= LW_HIDE_CURSOR;
} else {