From 73073e4f4209c874f2f41e270376a9802862df8f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 4 Oct 2014 23:52:50 +0000 Subject: [PATCH] afh: Make ->chunks_total and ->seconds_total fixed-size. These members of struct afh_info are stored as 4-byte quantities in the serialized afhi blob created by save_afhi(), so the structure should declare them as uint32_t rather than unsigned long. Fortunately, this bug is benign since save_afhi() uses the write_u32() helper from portable_io.h which does the right thing, regardless of the type of the variable passed. --- aac_afh.c | 6 +++--- afh.h | 4 ++-- afh_common.c | 4 ++-- afh_recv.c | 4 ++-- aft.c | 6 ++++-- mp3_afh.c | 2 +- ogg_afh_common.c | 2 +- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/aac_afh.c b/aac_afh.c index 5b2e9fba..04d74e8e 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -174,7 +174,7 @@ static ssize_t aac_compute_chunk_table(struct afh_info *afhi, if (ret < 0) return ret; afhi->chunks_total = ret; - PARA_DEBUG_LOG("sz table has %lu entries\n", afhi->chunks_total); + PARA_DEBUG_LOG("sz table has %" PRIu32 " entries\n", afhi->chunks_total); afhi->chunk_table = para_malloc((afhi->chunks_total + 1) * sizeof(size_t)); for (i = 1; i <= afhi->chunks_total; i++) { if (skip + 4 > numbytes) @@ -189,7 +189,7 @@ static ssize_t aac_compute_chunk_table(struct afh_info *afhi, } static int aac_set_chunk_tv(struct afh_info *afhi, - mp4AudioSpecificConfig *mp4ASC, long unsigned *seconds) + mp4AudioSpecificConfig *mp4ASC, uint32_t *seconds) { float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023; struct timeval total; @@ -200,7 +200,7 @@ static int aac_set_chunk_tv(struct afh_info *afhi, ms = 1000.0 * afhi->chunks_total * tmp / mp4ASC->samplingFrequency; ms2tv(ms, &total); tv_divide(afhi->chunks_total, &total, &afhi->chunk_tv); - PARA_INFO_LOG("%luHz, %lus (%lu x %lums)\n", + PARA_INFO_LOG("%luHz, %lus (%" PRIu32 " x %lums)\n", mp4ASC->samplingFrequency, ms / 1000, afhi->chunks_total, tv2ms(&afhi->chunk_tv)); if (ms < 1000) diff --git a/afh.h b/afh.h index 62e38c02..7a30947a 100644 --- a/afh.h +++ b/afh.h @@ -28,9 +28,9 @@ struct taginfo { /** Audio format dependent information. */ struct afh_info { /** The number of chunks this audio file contains. */ - long unsigned chunks_total; + uint32_t chunks_total; /** The length of the audio file in seconds. */ - long unsigned seconds_total; + uint32_t seconds_total; /** Audio handler specific info about the file. */ char *techinfo; /** Id3 tags, vorbis comments, aac tags. */ diff --git a/afh_common.c b/afh_common.c index b1f8b25d..063ae8f0 100644 --- a/afh_common.c +++ b/afh_common.c @@ -367,9 +367,9 @@ unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **re "%s: %s\n" /* format */ "%s: %dHz\n" /* frequency */ "%s: %d\n" /* channels */ - "%s: %lu\n" /* seconds total */ + "%s: %" PRIu32 "\n" /* seconds total */ "%s: %lu: %lu\n" /* chunk time */ - "%s: %lu\n" /* num chunks */ + "%s: %" PRIu32 "\n" /* num chunks */ "%s: %s\n" /* techinfo */ "%s: %s\n" /* artist */ "%s: %s\n" /* title */ diff --git a/afh_recv.c b/afh_recv.c index ff794852..16463463 100644 --- a/afh_recv.c +++ b/afh_recv.c @@ -40,11 +40,11 @@ static int afh_execute(struct btr_node *btrn, const char *cmd, char **result) *result = NULL; if (!strcmp(cmd, "seconds_total")) { - *result = make_message("%lu", pard->afhi.seconds_total); + *result = make_message("%" PRIu32, pard->afhi.seconds_total); return 1; } if (!strcmp(cmd, "chunks_total")) { - *result = make_message("%lu", pard->afhi.chunks_total); + *result = make_message("%" PRIu32, pard->afhi.chunks_total); return 1; } if (!strcmp(cmd, "afhi")) { diff --git a/aft.c b/aft.c index 35e513ff..7f9e786c 100644 --- a/aft.c +++ b/aft.c @@ -921,12 +921,14 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, WRITE_STATUS_ITEM(b, SI_FREQUENCY, "%dHz\n", afhi->frequency); WRITE_STATUS_ITEM(b, SI_CHANNELS, "%d\n", afhi->channels); WRITE_STATUS_ITEM(b, SI_DURATION, "%s\n", duration_buf); - WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%lu\n", afhi->seconds_total); + 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_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, "%lu\n", afhi->chunks_total); + WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%" PRIu32 "\n", + afhi->chunks_total); WRITE_STATUS_ITEM(b, SI_TECHINFO, "%s\n", afhi->techinfo); WRITE_STATUS_ITEM(b, SI_ARTIST, "%s\n", afhi->tags.artist); WRITE_STATUS_ITEM(b, SI_TITLE, "%s\n", afhi->tags.title); diff --git a/mp3_afh.c b/mp3_afh.c index 484172ab..73e744ec 100644 --- a/mp3_afh.c +++ b/mp3_afh.c @@ -656,7 +656,7 @@ static int mp3_read_info(unsigned char *map, size_t numbytes, int fd, afhi->channels = header_channels(&header); afhi->seconds_total = (tv2ms(&total_time) + 500) / 1000; tv_divide(afhi->chunks_total, &total_time, &afhi->chunk_tv); - PARA_DEBUG_LOG("%lu chunks, each %lums\n", afhi->chunks_total, + PARA_DEBUG_LOG("%" PRIu32 "chunks, each %lums\n", afhi->chunks_total, tv2ms(&afhi->chunk_tv)); ret = mp3_get_id3(map, numbytes, fd, &afhi->tags); afhi->techinfo = make_message("%cbr, %s, %s tags", vbr? 'v' : 'c', diff --git a/ogg_afh_common.c b/ogg_afh_common.c index b8b0006d..e49b803b 100644 --- a/ogg_afh_common.c +++ b/ogg_afh_common.c @@ -159,7 +159,7 @@ int ogg_get_file_info(char *map, size_t numbytes, struct afh_info *afhi, afhi->seconds_total = num_frames / afhi->frequency; /* use roughly one page per chunk */ frames_per_chunk = num_frames / i; - PARA_INFO_LOG("%lu seconds, %d frames/chunk\n", + PARA_INFO_LOG("%" PRIu32 "seconds, %d frames/chunk\n", afhi->seconds_total, frames_per_chunk); ct_size = 250; afhi->chunk_table = para_malloc(ct_size * sizeof(uint32_t)); -- 2.39.2