Slight cleanup to MV_GetVorbisCommentLoops(). The biggest change here is swapping calls to atol to our Batol macro, which is actually backed by strtol instead of atol.

git-svn-id: https://svn.eduke32.com/eduke32@7284 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-12-15 01:39:57 +00:00
parent 91096d2415
commit c3f88abf73

View file

@ -67,10 +67,10 @@ static void MV_GetVorbisCommentLoops(VoiceNode *voice, vorbis_comment *vc)
for (int comment = 0; comment < vc->comments; ++comment) for (int comment = 0; comment < vc->comments; ++comment)
{ {
const char *entry = (const char *)vc->user_comments[comment]; auto entry = (const char *)vc->user_comments[comment];
if (entry != NULL && entry[0] != '\0') if (entry != NULL && entry[0] != '\0')
{ {
const char *value = strchr(entry, '='); const char *value = Bstrchr(entry, '=');
if (!value) if (!value)
continue; continue;
@ -80,22 +80,22 @@ static void MV_GetVorbisCommentLoops(VoiceNode *voice, vorbis_comment *vc)
for (size_t t = 0; t < loopStartTagCount && vc_loopstart == NULL; ++t) for (size_t t = 0; t < loopStartTagCount && vc_loopstart == NULL; ++t)
{ {
char const * const tag = loopStartTags[t]; auto tag = loopStartTags[t];
if (field == strlen(tag) && Bstrncasecmp(entry, tag, field) == 0) if (field == Bstrlen(tag) && Bstrncasecmp(entry, tag, field) == 0)
vc_loopstart = value; vc_loopstart = value;
} }
for (size_t t = 0; t < loopEndTagCount && vc_loopend == NULL; ++t) for (size_t t = 0; t < loopEndTagCount && vc_loopend == NULL; ++t)
{ {
char const * const tag = loopEndTags[t]; auto tag = loopEndTags[t];
if (field == strlen(tag) && Bstrncasecmp(entry, tag, field) == 0) if (field == Bstrlen(tag) && Bstrncasecmp(entry, tag, field) == 0)
vc_loopend = value; vc_loopend = value;
} }
for (size_t t = 0; t < loopLengthTagCount && vc_looplength == NULL; ++t) for (size_t t = 0; t < loopLengthTagCount && vc_looplength == NULL; ++t)
{ {
char const * const tag = loopLengthTags[t]; auto tag = loopLengthTags[t];
if (field == strlen(tag) && Bstrncasecmp(entry, tag, field) == 0) if (field == Bstrlen(tag) && Bstrncasecmp(entry, tag, field) == 0)
vc_looplength = value; vc_looplength = value;
} }
} }
@ -103,20 +103,18 @@ static void MV_GetVorbisCommentLoops(VoiceNode *voice, vorbis_comment *vc)
if (vc_loopstart != NULL) if (vc_loopstart != NULL)
{ {
const ogg_int64_t ov_loopstart = Batol(vc_loopstart);
if (ov_loopstart >= 0) // a loop starting at 0 is valid
{ {
const ogg_int64_t ov_loopstart = atol(vc_loopstart); voice->LoopStart = (const char *) (intptr_t) ov_loopstart;
if (ov_loopstart >= 0) // a loop starting at 0 is valid voice->LoopSize = 1;
{
voice->LoopStart = (const char *) (intptr_t) ov_loopstart;
voice->LoopSize = 1;
}
} }
} }
if (vc_loopend != NULL) if (vc_loopend != NULL)
{ {
if (voice->LoopSize > 0) if (voice->LoopSize > 0)
{ {
const ogg_int64_t ov_loopend = atol(vc_loopend); const ogg_int64_t ov_loopend = Batol(vc_loopend);
if (ov_loopend > 0) // a loop ending at 0 is invalid if (ov_loopend > 0) // a loop ending at 0 is invalid
voice->LoopEnd = (const char *) (intptr_t) ov_loopend; voice->LoopEnd = (const char *) (intptr_t) ov_loopend;
} }
@ -125,7 +123,7 @@ static void MV_GetVorbisCommentLoops(VoiceNode *voice, vorbis_comment *vc)
{ {
if (voice->LoopSize > 0 && voice->LoopEnd == 0) if (voice->LoopSize > 0 && voice->LoopEnd == 0)
{ {
const ogg_int64_t ov_looplength = atol(vc_looplength); const ogg_int64_t ov_looplength = Batol(vc_looplength);
if (ov_looplength > 0) // a loop of length 0 is invalid if (ov_looplength > 0) // a loop of length 0 is invalid
voice->LoopEnd = (const char *) ((intptr_t) ov_looplength + (intptr_t) voice->LoopStart); voice->LoopEnd = (const char *) ((intptr_t) ov_looplength + (intptr_t) voice->LoopStart);
} }