Skip to content

Commit a090def

Browse files
committed
libfoundation: MCRangeMake() audit
1 parent ff826d1 commit a090def

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

libfoundation/include/foundation-auto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ template <typename T, void (*FREE)(T)> class MCAutoCustomPointerArray
11661166
bool Resize(uindex_t p_new_size)
11671167
{
11681168
if (p_new_size < m_size)
1169-
FreeElements(MCRangeMake(p_new_size, m_size - p_new_size));
1169+
FreeElements(MCRangeMakeMinMax(p_new_size, m_size));
11701170

11711171
return MCMemoryResizeArray(p_new_size, m_ptr, m_size);
11721172
}

libfoundation/src/foundation-chunk.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ bool MCTextChunkIterator_Delimited::Next()
542542
MCRange t_found_range;
543543
// calculate the length of the line / item
544544
// AL-2015-02-10: [[ Bug 14532 ]] Use restricted range for delimiter search
545-
if (!MCStringFind(m_text, MCRangeMake(t_offset, m_length - t_offset), m_delimiter, m_options, &t_found_range))
545+
if (!MCStringFind(m_text, MCRangeMakeMinMax(t_offset, m_length), m_delimiter, m_options, &t_found_range))
546546
{
547547
m_range . length = m_length - m_range . offset;
548548
m_exhausted = true;
@@ -569,7 +569,7 @@ bool MCTextChunkIterator_Delimited::IsAmong(MCStringRef p_needle)
569569
// Otherwise we need to find p_needle and check to see if there is a delimiter either side.
570570
// This is because of the case where the delimiter is within p_needle - e.g.
571571
// "a,b" is among the items of "a,b,c,d" should return true.
572-
return MCChunkIsAmongTheChunksOfRange(p_needle, m_text, m_delimiter, m_options, MCRangeMake(m_range . offset, m_length - m_range . offset));
572+
return MCChunkIsAmongTheChunksOfRange(p_needle, m_text, m_delimiter, m_options, MCRangeMakeMinMax(m_range . offset, m_length));
573573
}
574574

575575
while (Next())
@@ -614,12 +614,12 @@ uindex_t MCTextChunkIterator_Delimited::ChunkOffset(MCStringRef p_needle, uindex
614614
if (!MCStringIsEmpty(p_needle))
615615
{
616616
uindex_t t_found_offset;
617-
if (!MCChunkOffsetOfChunkInRange(m_text, p_needle, m_delimiter, p_whole_matches, m_options, MCRangeMake(m_range . offset, m_length - m_range . offset), t_found_offset))
617+
if (!MCChunkOffsetOfChunkInRange(m_text, p_needle, m_delimiter, p_whole_matches, m_options, MCRangeMakeMinMax(m_range . offset, m_length), t_found_offset))
618618
return 0;
619619

620620
// Count the number of delimiters between the start of the first chunk
621621
// and the start of the found string.
622-
t_chunk_offset += MCStringCount(m_text, MCRangeMake(m_range . offset, t_found_offset - m_range . offset), m_delimiter, m_options);
622+
t_chunk_offset += MCStringCount(m_text, MCRangeMakeMinMax(m_range . offset, t_found_offset), m_delimiter, m_options);
623623

624624
// AL-2015-07-20: [[ Bug 15618 ]] If the chunk found is outside the specified range, return 0 (not found)
625625
if (p_end_offset != nil && t_chunk_offset > *p_end_offset)
@@ -637,12 +637,12 @@ uindex_t MCTextChunkIterator_Delimited::ChunkOffset(MCStringRef p_needle, uindex
637637

638638
if (p_whole_matches)
639639
{
640-
if (MCStringSubstringIsEqualTo(m_text, MCRangeMake(m_range . offset, m_length - m_range . offset), p_needle, m_options))
640+
if (MCStringSubstringIsEqualTo(m_text, MCRangeMakeMinMax(m_range . offset, m_length), p_needle, m_options))
641641
return t_chunk_offset;
642642
}
643643
else
644644
{
645-
if (MCStringSubstringContains(m_text, MCRangeMake(m_range . offset, m_length - m_range . offset), p_needle, m_options))
645+
if (MCStringSubstringContains(m_text, MCRangeMakeMinMax(m_range . offset, m_length), p_needle, m_options))
646646
return t_chunk_offset;
647647
}
648648
t_chunk_offset++;

libfoundation/src/foundation-java-private.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static bool __MCJavaCallNeedsClassInstance(MCJavaCallType p_type)
143143
static bool __RemoveSurroundingParentheses(MCStringRef p_in, MCStringRef& r_out)
144144
{
145145
return MCStringCopySubstring(p_in,
146-
MCRangeMake(1, MCStringGetLength(p_in) - 2),
146+
MCRangeMakeMinMax(1, MCStringGetLength(p_in) - 1),
147147
r_out);
148148
}
149149

libfoundation/src/foundation-string.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ bool MCStringMapIndices(MCStringRef self, MCBreakIteratorType p_type, MCLocaleRe
19181918
t_end = MCStringGetLength(self);
19191919

19201920
MCRange t_units;
1921-
t_units = MCRangeMake(t_start, t_end - t_start);
1921+
t_units = MCRangeMakeMinMax(t_start, t_end);
19221922

19231923
// All done
19241924
r_out_range = t_units;
@@ -1965,7 +1965,7 @@ bool MCStringMapGraphemeIndices(MCStringRef self, MCRange p_grapheme_range, MCRa
19651965
if (t_end == kMCLocaleBreakIteratorDone)
19661966
t_end = MCStringGetLength(self);
19671967

1968-
r_cu_range = MCRangeMake(t_start, t_end - t_start);
1968+
r_cu_range = MCRangeMakeMinMax(t_start, t_end);
19691969
return true;
19701970
}
19711971

@@ -2017,7 +2017,7 @@ bool MCStringMapTrueWordIndices(MCStringRef self, MCLocaleRef p_locale, MCRange
20172017
;
20182018

20192019
MCRange t_units;
2020-
t_units = MCRangeMake(t_start, t_word_range . offset + t_word_range . length - t_start);
2020+
t_units = MCRangeMakeMinMax(t_start, t_word_range . offset + t_word_range . length);
20212021

20222022
// All done
20232023
MCLocaleBreakIteratorRelease(t_iter);
@@ -3376,7 +3376,7 @@ bool MCStringFirstIndexOfStringInRange(MCStringRef self, MCStringRef p_needle, M
33763376
MC_DLLEXPORT_DEF
33773377
bool MCStringFirstIndexOfChar(MCStringRef self, codepoint_t p_needle, uindex_t p_after, MCStringOptions p_options, uindex_t& r_offset)
33783378
{
3379-
return MCStringFirstIndexOfCharInRange(self, p_needle, MCRangeMake(p_after, self -> char_count - p_after), p_options, r_offset);
3379+
return MCStringFirstIndexOfCharInRange(self, p_needle, MCRangeMakeMinMax(p_after, self -> char_count), p_options, r_offset);
33803380
}
33813381

33823382
MC_DLLEXPORT_DEF
@@ -3702,7 +3702,7 @@ bool MCStringDivideAtIndex(MCStringRef self, uindex_t p_offset, MCStringRef& r_h
37023702
return false;
37033703

37043704
MCStringRef t_tail;
3705-
if (!MCStringCopySubstring(self, MCRangeMake(p_offset + 1, MCStringGetLength(self) - p_offset - 1), t_tail))
3705+
if (!MCStringCopySubstring(self, MCRangeMakeMinMax(p_offset + 1, MCStringGetLength(self)), t_tail))
37063706
{
37073707
MCValueRelease(t_head);
37083708
return false;
@@ -3808,7 +3808,7 @@ static bool __MCStringSkip(MCStringRef self,
38083808
while(p_count > 0)
38093809
{
38103810
if (!__MCStringFind(self,
3811-
MCRangeMake(t_start, t_finish - t_start),
3811+
MCRangeMakeMinMax(t_start, t_finish),
38123812
p_needle,
38133813
p_options,
38143814
&t_last))
@@ -3867,7 +3867,7 @@ static uindex_t __MCStringCount(MCStringRef self,
38673867
MCRange t_last;
38683868
t_last = MCRangeMake(t_start, 0);
38693869
while(__MCStringFind(self,
3870-
MCRangeMake(t_start, t_finish - t_start),
3870+
MCRangeMakeMinMax(t_start, t_finish),
38713871
p_needle,
38723872
p_options,
38733873
&t_last))
@@ -3931,7 +3931,7 @@ static bool __MCStringDelimitedOffset(MCStringRef self,
39313931
// we are done.
39323932
MCRange t_found_range;
39333933
if (!__MCStringFind(self,
3934-
MCRangeMake(t_start, t_finish - t_start),
3934+
MCRangeMakeMinMax(t_start, t_finish),
39353935
p_needle,
39363936
p_options,
39373937
&t_found_range))
@@ -3940,7 +3940,7 @@ static bool __MCStringDelimitedOffset(MCStringRef self,
39403940
// We must now search for delimiters in the substring between the end of the
39413941
// previous delimiter and the start of the found range.
39423942
t_delimiter_count += __MCStringCount(self,
3943-
MCRangeMake(t_start, t_found_range . offset - t_start),
3943+
MCRangeMakeMinMax(t_start, t_found_range . offset),
39443944
p_delimiter,
39453945
p_options,
39463946
&t_prev_delimiter);

libfoundation/src/system-library-static.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ class __MCSLibraryHandleStatic
188188

189189
MCAutoStringRef t_leaf_name;
190190
if (!MCStringCopySubstring(p_native_path,
191-
MCRangeMake(t_last_separator,
192-
t_first_extension - t_last_separator),
191+
MCRangeMakeMinMax(t_last_separator,
192+
t_first_extension),
193193
&t_leaf_name))
194194
{
195195
return false;

0 commit comments

Comments
 (0)