Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 577706a

Browse files
committed
[[ Bug ]] Fix uses of MCStringCopyAndRelease.
1 parent e496778 commit 577706a

File tree

5 files changed

+17
-72
lines changed

5 files changed

+17
-72
lines changed

engine/src/fieldrtf.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,13 @@ bool MCField::exportasrtftext(uint32_t p_part_id, int32_t p_start_index, int32_t
873873
/* UNCHECKED */ MCStringAppendFormat(ctxt.m_text, "\n}");
874874

875875
// Return the buffer.
876-
return MCStringCopyAndRelease(ctxt.m_text, r_string);
876+
if (!MCStringCopyAndRelease(ctxt.m_text, r_string))
877+
{
878+
MCValueRelease(ctxt . m_text);
879+
return false;
880+
}
881+
882+
return true;
877883
}
878884

879885
////////////////////////////////////////////////////////////////////////////////

engine/src/syscfdate.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ static bool osx_cf_fetch_format(CFLocaleRef p_locale, CFDateFormatterStyle p_dat
370370
CFRelease(t_formatter);
371371

372372
if (t_success)
373-
MCStringCopyAndRelease(t_format, r_string);
374-
else
373+
t_success = MCStringCopyAndRelease(t_format, r_string);
374+
375+
if (!t_success)
375376
MCValueRelease(t_format);
376377

377378
return t_success;

libfoundation/src/foundation-list.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -254,69 +254,3 @@ bool __MCListImmutableCopy(__MCList *self, bool p_release, __MCList*& r_immutabl
254254
}
255255

256256
////////////////////////////////////////////////////////////////////////////////
257-
258-
#if 0
259-
bool MCListCreateMutable(char p_delimiter, MCListRef& r_list)
260-
{
261-
MCListRef self;
262-
if (!MCMemoryNew(self))
263-
return false;
264-
265-
if (!MCStringCreateMutable(0, self -> buffer))
266-
{
267-
MCMemoryDelete(self);
268-
return false;
269-
}
270-
271-
self -> delimiter = p_delimiter;
272-
273-
r_list = self;
274-
return true;
275-
}
276-
277-
void MCListDestroy(MCListRef self)
278-
{
279-
MCValueRelease(self -> buffer);
280-
MCMemoryDelete(self);
281-
}
282-
283-
bool MCListCopyAsStringAndRelease(MCListRef self, MCStringRef& r_string)
284-
{
285-
if (!MCStringCopyAndRelease(self -> buffer, r_string))
286-
return false;
287-
288-
MCMemoryDelete(self);
289-
290-
return true;
291-
}
292-
293-
bool MCListAppend(MCListRef self, MCStringRef p_string)
294-
{
295-
if (MCStringGetLength(self -> buffer) != 0 &&
296-
!MCStringAppendNativeChars(self -> buffer, &self -> delimiter, 1))
297-
return false;
298-
299-
return MCStringAppend(self -> buffer, p_string);
300-
}
301-
302-
bool MCListAppendCString(MCListRef self, const char *p_cstring)
303-
{
304-
return MCListAppendNativeChars(self, p_cstring, MCCStringLength(p_cstring));
305-
}
306-
307-
bool MCListAppendOldString(MCListRef self, const MCString& p_oldstring)
308-
{
309-
return MCListAppendNativeChars(self, p_oldstring . getstring(), p_oldstring . getlength());
310-
}
311-
312-
bool MCListAppendNativeChars(MCListRef self, const char *p_chars, uindex_t p_char_count)
313-
{
314-
if (MCStringGetLength(self -> buffer) != 0 &&
315-
!MCStringAppendNativeChars(self -> buffer, &self -> delimiter, 1))
316-
return false;
317-
318-
return MCStringAppendNativeChars(self -> buffer, p_chars, p_char_count);
319-
}
320-
#endif
321-
322-
////////////////////////////////////////////////////////////////////////////////

libfoundation/src/foundation-set.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,12 @@ bool __MCSetCopyDescription(__MCSet *self, MCStringRef& r_string)
349349
if (t_success)
350350
t_success = MCStringAppendFormat(t_string, "}");
351351
if (t_success)
352-
return MCStringCopyAndRelease(t_string, r_string);
352+
t_success = MCStringCopyAndRelease(t_string, r_string);
353353

354-
MCValueRelease(t_string);
354+
if (!t_success)
355+
MCValueRelease(t_string);
355356

356-
return false;
357+
return t_success;
357358
}
358359

359360
bool __MCSetImmutableCopy(__MCSet *self, bool p_release, __MCSet*& r_immutable_value)

libfoundation/src/foundation-string.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ bool MCStringFormatV(MCStringRef& r_string, const char *p_format, va_list p_args
814814

815815
if (t_success)
816816
t_success = MCStringCopyAndRelease(t_buffer, r_string);
817+
818+
if (!t_success)
819+
MCValueRelease (t_buffer);
817820

818821
return t_success;
819822
}

0 commit comments

Comments
 (0)