Skip to content

Commit 0ac7698

Browse files
committed
Merge pull request livecode#1776 from peter-b/coverity
Fix defects detected by Coverity Scan.
2 parents 607ef20 + 6c0be6d commit 0ac7698

4 files changed

Lines changed: 38 additions & 25 deletions

File tree

engine/src/foundation-legacy.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool MCCStringClone(const char *p_string, char *& r_new_string)
4646
return true;
4747
}
4848

49-
if (!MCMemoryAllocate(p_string == nil ? 1 : strlen(p_string) + 1, r_new_string))
49+
if (!MCMemoryAllocate(strlen(p_string) + 1, r_new_string))
5050
return false;
5151
strcpy(r_new_string, p_string);
5252
return true;
@@ -305,11 +305,13 @@ bool MCCStringFromUnicodeSubstring(const unichar_t *p_chars, uint32_t p_char_cou
305305

306306
bool MCCStringFromUnicode(const unichar_t *p_unicode_string, char*& r_string)
307307
{
308+
if (NULL == p_unicode_string)
309+
return false;
310+
308311
uint32_t t_wstring_length;
309312
t_wstring_length = 0;
310-
if (p_unicode_string != nil)
311-
while(p_unicode_string[t_wstring_length] != 0)
312-
t_wstring_length++;
313+
while(p_unicode_string[t_wstring_length] != 0)
314+
t_wstring_length++;
313315

314316
return MCCStringFromUnicodeSubstring(p_unicode_string, t_wstring_length, r_string);
315317
}
@@ -1905,7 +1907,8 @@ bool deserialize_data(const char *p_stream, uint32_t p_stream_size, uint32_t &r_
19051907
if (r_data == nil)
19061908
{
19071909
t_size = t_data_size;
1908-
MCMemoryAllocate(t_size, t_data);
1910+
if (!MCMemoryAllocate(t_size, t_data))
1911+
return false;
19091912
}
19101913
else
19111914
{

engine/src/lnxtransfer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ GdkAtom *MCGdkTransferStore::QueryAtoms(size_t &r_count)
595595
for (uint32_t i = 0; i < m_entry_count; i++)
596596
{
597597
t_index = find_table_entry_with_full_types(m_entries[i].m_type, m_entries[i].m_mime);
598+
if (0 > t_index)
599+
continue;
600+
598601
if (XTransfer_lookup_table[t_index].priority > t_top)
599602
t_top = XTransfer_lookup_table[t_index].priority;
600603
}
@@ -710,7 +713,7 @@ bool MCGdkTransferStore::Query(MCTransferType* &r_types, size_t &r_type_count)
710713
for (uint32_t i = 0; i < m_entry_count; i++)
711714
{
712715
t_index = find_table_entry_with_full_types(m_entries[i].m_type, m_entries[i].m_mime);
713-
if (-1 == t_index)
716+
if (0 > t_index)
714717
continue;
715718

716719
if (XTransfer_lookup_table[t_index].priority > t_top)
@@ -720,7 +723,7 @@ bool MCGdkTransferStore::Query(MCTransferType* &r_types, size_t &r_type_count)
720723
for (uint32_t i = 0; i < m_entry_count; i++)
721724
{
722725
t_index = find_table_entry_with_full_types(m_entries[i].m_type, m_entries[i].m_mime);
723-
if (-1 == t_index)
726+
if (0 > t_index)
724727
continue;
725728

726729
if ((XTransfer_lookup_table[t_index].priority == t_top) && should_include(t_list.Ptr(), t_count, m_entries[i].m_type))

libscript/src/script-builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ void MCScriptEndHandlerInModule(MCScriptModuleBuilderRef self)
11421142
t_target_address = self -> instructions[self -> labels[t_operands[t_address_index] - 1] . instruction] . address - t_address;
11431143

11441144
uindex_t t_encoded_target_address;
1145-
if (t_target_address > 0)
1145+
if (t_target_address >= 0)
11461146
t_encoded_target_address = t_target_address * 2;
11471147
else if (t_target_address < 0)
11481148
t_encoded_target_address = (-t_target_address) * 2 + 1;

libscript/src/script-instance.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,10 @@ static bool MCScriptPerformScriptInvoke(MCScriptFrame*& x_frame, byte_t*& x_next
838838
if (t_needs_mapping)
839839
{
840840
if (!MCMemoryNewArray(p_arity, t_callee -> mapping))
841+
{
842+
MCScriptDestroyFrame (t_callee);
841843
return false;
844+
}
842845

843846
MCMemoryCopy(t_callee -> mapping, p_arguments, sizeof(int) * p_arity);
844847
}
@@ -888,6 +891,7 @@ static bool __split_binding(MCStringRef& x_string, codepoint_t p_char, MCStringR
888891
else
889892
{
890893
MCValueRelease(x_string);
894+
MCValueRelease(t_tail);
891895
x_string = t_head;
892896
}
893897

@@ -2169,30 +2173,33 @@ bool MCScriptCallHandlerOfInstanceInternal(MCScriptInstanceRef self, MCScriptHan
21692173
if (t_handler_definition -> function == nil)
21702174
{
21712175
if (!MCScriptPrepareForeignFunction(t_frame, t_instance, t_handler_definition, false, t_bound))
2172-
return false;
2176+
t_success = false;
21732177
}
21742178
else
21752179
t_bound = true;
21762180

2177-
if (t_bound)
2181+
if (t_success)
21782182
{
2179-
// The context struct is 'moved' into the handlerref.
2180-
__MCScriptHandlerContext t_context;
2181-
t_context . instance = MCScriptRetainInstance(t_instance);
2182-
t_context . definition = t_handler_definition;
2183+
if (t_bound)
2184+
{
2185+
// The context struct is 'moved' into the handlerref.
2186+
__MCScriptHandlerContext t_context;
2187+
t_context . instance = MCScriptRetainInstance(t_instance);
2188+
t_context . definition = t_handler_definition;
21832189

2184-
MCHandlerRef t_value;
2185-
t_success = MCHandlerCreate(t_signature, &__kMCScriptHandlerCallbacks, &t_context, t_value);
2190+
MCHandlerRef t_value;
2191+
t_success = MCHandlerCreate(t_signature, &__kMCScriptHandlerCallbacks, &t_context, t_value);
21862192

2187-
if (t_success)
2188-
{
2189-
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, t_value);
2190-
MCValueRelease(t_value);
2191-
}
2192-
}
2193-
else
2194-
{
2195-
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, kMCNull);
2193+
if (t_success)
2194+
{
2195+
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, t_value);
2196+
MCValueRelease(t_value);
2197+
}
2198+
}
2199+
else
2200+
{
2201+
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, kMCNull);
2202+
}
21962203
}
21972204
}
21982205
}

0 commit comments

Comments
 (0)