mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
better handling for OSs with small RAND_MAX (SF#1783630: https://sourceforge.net/tracker/index.php?func=detail&aid=1783630&group_id=13478&atid=113478)
This commit is contained in:
@@ -108,7 +108,7 @@
|
|||||||
<li>Fixed bug where sometimes an existing installation of flac could interfere with the build process (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1763690&group_id=13478&atid=113478">SF #1763690</a>).</li>
|
<li>Fixed bug where sometimes an existing installation of flac could interfere with the build process (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1763690&group_id=13478&atid=113478">SF #1763690</a>).</li>
|
||||||
<li>OS X fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1786225&group_id=13478&atid=313478">SF #1786225</a>).</li>
|
<li>OS X fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1786225&group_id=13478&atid=313478">SF #1786225</a>).</li>
|
||||||
<li>MinGW fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1684879&group_id=13478&atid=113478">SF #1684879</a>).</li>
|
<li>MinGW fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1684879&group_id=13478&atid=113478">SF #1684879</a>).</li>
|
||||||
<li>Solaris 10 fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1783225&group_id=13478&atid=113478">SF #1783225</a>).</li>
|
<li>Solaris 10 fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1783225&group_id=13478&atid=113478">SF #1783225</a> <a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1783630&group_id=13478&atid=113478">SF #1783630</a>).</li>
|
||||||
<li>OS/2 fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1771378&group_id=13478&atid=113478">SF #1771378</a> <a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1229495&group_id=13478&atid=113478">SF #1229495</a>).</li>
|
<li>OS/2 fixes (<a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1771378&group_id=13478&atid=113478">SF #1771378</a> <a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1229495&group_id=13478&atid=113478">SF #1229495</a>).</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -75,6 +75,21 @@ static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned local_rand_(void)
|
||||||
|
{
|
||||||
|
#if !defined _MSC_VER && !defined __MINGW32__
|
||||||
|
#define RNDFUNC random
|
||||||
|
#else
|
||||||
|
#define RNDFUNC rand
|
||||||
|
#endif
|
||||||
|
/* every RAND_MAX I've ever seen is 2^15-1 or 2^31-1, so a little hackery here: */
|
||||||
|
if (RAND_MAX > 32767)
|
||||||
|
return RNDFUNC();
|
||||||
|
else /* usually MSVC, some solaris */
|
||||||
|
return (RNDFUNC()<<15) | RNDFUNC();
|
||||||
|
#undef RNDFUNC
|
||||||
|
}
|
||||||
|
|
||||||
static off_t get_filesize_(const char *srcpath)
|
static off_t get_filesize_(const char *srcpath)
|
||||||
{
|
{
|
||||||
struct stat srcstat;
|
struct stat srcstat;
|
||||||
@@ -298,12 +313,6 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
|
|||||||
printf("file's total_samples is %I64u\n", decoder_client_data.total_samples);
|
printf("file's total_samples is %I64u\n", decoder_client_data.total_samples);
|
||||||
#else
|
#else
|
||||||
printf("file's total_samples is %llu\n", (unsigned long long)decoder_client_data.total_samples);
|
printf("file's total_samples is %llu\n", (unsigned long long)decoder_client_data.total_samples);
|
||||||
#endif
|
|
||||||
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
|
|
||||||
if (decoder_client_data.total_samples > (FLAC__uint64)RAND_MAX) {
|
|
||||||
printf("ERROR: must be total_samples < %u\n", (unsigned)RAND_MAX);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
n = (long int)decoder_client_data.total_samples;
|
n = (long int)decoder_client_data.total_samples;
|
||||||
|
|
||||||
@@ -315,10 +324,6 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
|
|||||||
if(n == 0) {
|
if(n == 0) {
|
||||||
/* 8 would imply no compression, 9 guarantees that we will get some samples off the end of the stream to test that case */
|
/* 8 would imply no compression, 9 guarantees that we will get some samples off the end of the stream to test that case */
|
||||||
n = 9 * filesize / (decoder_client_data.channels * decoder_client_data.bits_per_sample);
|
n = 9 * filesize / (decoder_client_data.channels * decoder_client_data.bits_per_sample);
|
||||||
#if !defined _MSC_VER && !defined __MINGW32__
|
|
||||||
if(n > RAND_MAX)
|
|
||||||
n = RAND_MAX;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Begin seek barrage, count=%u\n", count);
|
printf("Begin seek barrage, count=%u\n", count);
|
||||||
@@ -339,12 +344,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
|
|||||||
pos = n + (i-20);
|
pos = n + (i-20);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#if !defined _MSC_VER && !defined __MINGW32__
|
pos = (FLAC__uint64)(local_rand_() % n);
|
||||||
pos = (FLAC__uint64)(random() % n);
|
|
||||||
#else
|
|
||||||
/* RAND_MAX is only 32767 in my MSVC */
|
|
||||||
pos = (FLAC__uint64)((rand()<<15|rand()) % n);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|||||||
Reference in New Issue
Block a user