aft: Check return value of load_afsi().
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index df295246db0cf1d1d6e3d0b202d43c86332db0f6..1afc16bc542b3812687af3a58df97b941586d885 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -738,11 +738,11 @@ static void get_duration_buf(int seconds, char *buf, struct ls_options *opts)
        if (!hours) { /* m:ss or mm:ss */
                max_width = opts->mode == LS_MODE_LONG?
                        opts->widths.duration_width : 4;
-               sprintf(buf, "%*u:%02u", max_width - 3, mins, seconds % 60);
+               sprintf(buf, "%*u:%02d", max_width - 3, mins, seconds % 60);
        } else { /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */
                max_width = opts->mode == LS_MODE_LONG?
                        opts->widths.duration_width : 7;
-               sprintf(buf, "%*u:%02u:%02u", max_width - 6, hours, mins,
+               sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins,
                        seconds % 60);
        }
 }
@@ -876,14 +876,14 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts,
                para_printf(b,
                        "%s "   /* attributes */
                        "%*u "  /* amp */
-                       "%*d "  /* image_id  */
-                       "%*d "  /* lyrics_id */
-                       "%*d "  /* bitrate */
+                       "%*u "  /* image_id  */
+                       "%*u "  /* lyrics_id */
+                       "%*u "  /* bitrate */
                        "%*s "  /* audio format */
-                       "%*d "  /* frequency */
-                       "%d "   /* channels */
+                       "%*u "  /* frequency */
+                       "%u "   /* channels */
                        "%s "   /* duration */
-                       "%*d "  /* num_played */
+                       "%*u "  /* num_played */
                        "%s "   /* last_played */
                        "%s\n", /* path */
                        att_buf,
@@ -930,7 +930,7 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts,
        WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%" PRIu32 "\n",
                afhi->seconds_total);
        WRITE_STATUS_ITEM(b, SI_LAST_PLAYED, "%s\n", last_played_time);
-       WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%d\n", afsi->num_played);
+       WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%u\n", afsi->num_played);
        WRITE_STATUS_ITEM(b, SI_AMPLIFICATION, "%u\n", afsi->amp);
        WRITE_STATUS_ITEM(b, SI_CHUNK_TIME, "%lu\n", tv2ms(&afhi->chunk_tv));
        WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%" PRIu32 "\n",
@@ -2044,6 +2044,22 @@ static int com_touch_callback(struct afs_callback_arg *aca)
                .data = aca,
                .action = touch_audio_file
        };
+       if (cto->image_id >= 0) {
+               ret = img_get_name_by_id(cto->image_id, NULL);
+               if (ret < 0) {
+                       para_printf(&aca->pbout, "invalid image ID: %d\n",
+                               cto->image_id);
+                       return ret;
+               }
+       }
+       if (cto->lyrics_id >= 0) {
+               ret = lyr_get_name_by_id(cto->lyrics_id, NULL);
+               if (ret < 0) {
+                       para_printf(&aca->pbout, "invalid lyrics ID: %d\n",
+                               cto->lyrics_id);
+                       return ret;
+               }
+       }
        if (cto->flags & TOUCH_FLAG_FNM_PATHNAME)
                pmd.fnmatch_flags |= FNM_PATHNAME;
        ret = for_each_matching_row(&pmd);
@@ -2256,7 +2272,9 @@ static int copy_selector_info(__a_unused struct osl_table *table,
        ret = get_afsi_object_of_row(row, &target_afsi_obj);
        if (ret < 0)
                return ret;
-       load_afsi(&target_afsi, &target_afsi_obj);
+       ret = load_afsi(&target_afsi, &target_afsi_obj);
+       if (ret < 0)
+               return ret;
        old_afsi = target_afsi;
        if (cad->flags & CPSI_FLAG_COPY_LYRICS_ID)
                target_afsi.lyrics_id = cad->source_afsi.lyrics_id;
@@ -2625,7 +2643,7 @@ static int aft_open(const char *dir)
        if (ret >= 0) {
                unsigned num;
                osl_get_num_rows(audio_file_table, &num);
-               PARA_INFO_LOG("audio file table contains %d files\n", num);
+               PARA_INFO_LOG("audio file table contains %u files\n", num);
                return ret;
        }
        PARA_NOTICE_LOG("failed to open audio file table\n");