]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mood.c
afs: Update dummy mood assumptions to reflect the reality.
[paraslash.git] / mood.c
diff --git a/mood.c b/mood.c
index a63d4d2af5d10d7b64c319d915e00b9b7ea62e89..5268e77fe03c7e56d1b146935f683e30dea9a2f6 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -857,8 +857,7 @@ void close_current_mood(void)
  *
  * If there is already an open mood, it will be closed first.
  *
- * \return Positive on success, negative on errors. Loading the dummy mood
- * always succeeds.
+ * \return Positive on success, negative on errors.
  *
  * \sa struct \ref afs_info::last_played, \ref mp_eval_row().
  */
@@ -873,10 +872,14 @@ int change_current_mood(const char *mood_name, char **errmsg)
        if (mood_name) {
                struct mood *m;
                struct osl_row *row;
-               struct osl_object obj = {
-                       .data = (char *)mood_name,
-                       .size = strlen(mood_name) + 1
-               };
+               struct osl_object obj;
+
+               if (!*mood_name) {
+                       *errmsg = make_message("empty mood name");
+                       return -ERRNO_TO_PARA_ERROR(EINVAL);
+               }
+               obj.data = (char *)mood_name;
+               obj.size = strlen(mood_name) + 1;
                ret = osl(osl_get_row(moods_table, BLOBCOL_NAME, &obj, &row));
                if (ret < 0) {
                        if (errmsg)
@@ -899,7 +902,7 @@ int change_current_mood(const char *mood_name, char **errmsg)
        if (ret < 0) {
                if (errmsg)
                        *errmsg = make_message("audio file loop failed");
-               return ret;
+               goto out;
        }
        for (i = 0; i < statistics.num; i++) {
                struct admissible_file_info *a = aa.array + i;
@@ -915,6 +918,8 @@ int change_current_mood(const char *mood_name, char **errmsg)
        ret = statistics.num;
 out:
        free(aa.array);
+       if (ret < 0)
+               close_current_mood();
        return ret;
 }