[PATCH] frontend: cast long-to-int narrowing conversions in get_audio.c

"Maya R. Odinezenko via Lame-dev" <[email protected]> Tue, 21 Jul 2026 18:53:57 -0400
Newsgroups gmane.comp.audio.mp3.lame
Message-ID <CAFCgL3nWQwhMSyq3aw62WoEdwwBUrmWj1Z=YF3_==7Vfd=zbeQ@mail.gmail.com>
Hello,

Small follow-up to the warning-cleanup series: on LP64 builds
(macOS, 64-bit Linux) the frontend audio reader has ten implicit
long-to-int conversions that Apple Clang flags under the Xcode
default warning set. The values are all bounded by API contracts
and existing range checks, so this just makes the narrowing
explicit.

-- >8 --
From 7dbf386b9e5f555f002f5e1f287f9dbd0cdb06fc Mon Sep 17 00:00:00 2001
From: Maya <[email protected]>
Date: Tue, 21 Jul 2026 18:42:17 -0400
Subject: [PATCH] frontend: silence LP64 narrowing warnings in get_audio.c

On LP64 platforms (macOS, 64-bit Linux), several assignments in the
frontend audio reader implicitly convert wider integer types to int.
Apple Clang under Xcode reports these conversions with
-Wshorten-64-to-32.

Add explicit casts at the conversion boundaries. The affected values
are already constrained by API contracts and existing range checks;
the casts document the intended types without changing runtime
behavior.

The totalframes conversion remains protected by the existing INT_MAX
range check introduced in r6605.

Verified: warning-clean build under Apple Clang 21 with the Xcode
default warning set; encoded and decoded output unchanged.
---
 frontend/get_audio.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/frontend/get_audio.c b/frontend/get_audio.c
index e95b03f..68ffe7a 100644
--- a/frontend/get_audio.c
+++ b/frontend/get_audio.c
@@ -605,12 +605,12 @@ setSkipStartAndEnd(lame_t gfp, int enc_delay,
int enc_padding)
         if (skip_start == 0) {
             if (enc_delay > -1 || enc_padding > -1) {
                 if (enc_delay > -1)
-                    skip_start = enc_delay + dec_delay;
+                    skip_start = (int)(enc_delay + dec_delay);
                 if (enc_padding > -1)
-                    skip_end = enc_padding - dec_delay;
+                    skip_end = (int)(enc_padding - dec_delay);
             }
             else
-                skip_start = lame_get_encoder_delay(gfp) + dec_delay;
+                skip_start = (int)(lame_get_encoder_delay(gfp) + dec_delay);
         }
         else {
             /* user specified a value of skip. just add for decoder */
@@ -824,10 +824,10 @@ get_audio_common(lame_t gfp, int
buffer[2][1152], short buffer16[2][1152])
         unsigned int tmp_num_samples, remaining;
         /* get num_samples */
         if (is_mpeg_file_format(global_reader.input_format)) {
-            tmp_num_samples = global_decoder.mp3input_data.nsamp;
+            tmp_num_samples = (unsigned int)global_decoder.mp3input_data.nsamp;
         }
         else {
-            tmp_num_samples = lame_get_num_samples(gfp);
+            tmp_num_samples = (unsigned int)lame_get_num_samples(gfp);
         }
         if (global.num_samples_read < tmp_num_samples) {
             remaining = tmp_num_samples - global.num_samples_read;
@@ -956,7 +956,7 @@ read_samples_mp3(LAME_UNUSED lame_t gfp,
LAME_UNUSED FILE * musicin,
         }
         return -1;
     }
-    out = outbytes/(sizeof(short)*global_decoder.mp3input_data.stereo);
+    out = (int)(outbytes/(sizeof(short)*global_decoder.mp3input_data.stereo));
     if (global_decoder.mp3input_data.stereo == 2) {
         int i;
         for (i=0; i<out; ++i) {
@@ -2111,7 +2111,7 @@ int lame123_decode_initfile(FILE *fd,
mp3data_struct *mp3data, int *enc_delay, i
     /* I am paranoid about off_t being larger than long or int. */
     len = mpg123_framelength(global.hip->mh);
     if(len <= ((unsigned int)-1)/2)     /* totalframes is int, bound
to INT_MAX */
-        mp3data->totalframes = len;
+        mp3data->totalframes = (int)len;
     else
         return -1;
     len = mpg123_length(global.hip->mh);
@@ -2122,9 +2122,9 @@ int lame123_decode_initfile(FILE *fd,
mp3data_struct *mp3data, int *enc_delay, i
     /* Encoder delay and padding are not needed when libmpg123 handles gapless
        decoding itself. So let's see if we get away with that. */
     mpg123_getstate(global.hip->mh, MPG123_ENC_DELAY, &val, NULL);
-    *enc_delay = val;
+    *enc_delay = (int)val;
     mpg123_getstate(global.hip->mh, MPG123_ENC_PADDING, &val, NULL);
-    *enc_padding = val;
+    *enc_padding = (int)val;
     if(global.in_id3v2_tag)
         free(global.in_id3v2_tag);
     global.in_id3v2_size = 0;
@@ -2141,7 +2141,7 @@ int lame123_decode_initfile(FILE *fd,
mp3data_struct *mp3data, int *enc_delay, i
     /* How much of this is actually needed for the frontend? */
     mp3data->header_parsed = 1;
     mp3data->stereo = channels; /* Channel count correct? Or is dual
mono different? */
-    mp3data->samplerate = rate;
+    mp3data->samplerate = (int)rate;
     mp3data->mode = fi.mode;
     mp3data->mode_ext = fi.mode_ext;
     mp3data->framesize = mpg123_spf(global.hip->mh);
-- 
2.50.1 (Apple Git-155)