return max;
}
-static void load_chunk_table(struct afh_info *afhi, char *buf)
+static void load_chunk_table(struct afh_info *afhi, const struct osl_object *ct)
{
int i;
afhi->chunk_table = para_malloc(sizeof_chunk_table(afhi));
- for (i = 0; i <= afhi->chunks_total; i++)
- afhi->chunk_table[i] = read_u32(buf + 4 * i);
+ for (i = 0; i <= afhi->chunks_total && i * 4 + 3 < ct->size; i++)
+ afhi->chunk_table[i] = read_u32(ct->data + 4 * i);
}
/**
{
void *shm_afd;
int ret;
+ struct osl_object obj;
ret = shm_attach(shmid, ATTACH_RO, &shm_afd);
if (ret < 0)
return ret;
+ ret = shm_size(shmid, &obj.size);
+ if (ret < 0)
+ goto detach;
*afd = *(struct audio_file_data *)shm_afd;
- load_chunk_table(&afd->afhi, shm_afd + sizeof(*afd));
+ obj.data = shm_afd + sizeof(*afd);
+ obj.size -= sizeof(*afd);
+ load_chunk_table(&afd->afhi, &obj);
+ ret = 1;
+detach:
shm_detach(shm_afd);
- return 1;
+ return ret;
}
static int get_local_time(uint64_t *seconds, char *buf, size_t size,
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);
}
}
(long unsigned) d->afhi.chunk_tv.tv_usec
);
buf = chunk_table_obj.data;
- for (i = 0; i <= d->afhi.chunks_total; i++)
+ for (
+ i = 0;
+ i <= d->afhi.chunks_total && 4 * i + 3 < chunk_table_obj.size;
+ i++
+ )
para_printf(b, "%u ", (unsigned) read_u32(buf + 4 * i));
para_printf(b, "\n");
ret = 1;
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,
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",
save_afsi(&new_afsi, &afsi_obj); /* in-place update */
afd->audio_format_id = d->afsi.audio_format_id;
- load_chunk_table(&afd->afhi, chunk_table_obj.data);
+ load_chunk_table(&afd->afhi, &chunk_table_obj);
aced.aft_row = current_aft_row;
aced.old_afsi = &d->afsi;
/*
.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);
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");