Skip to content

Commit eddea6c

Browse files
[[ UninitialisedVars ]] Update pull request after Peter's comments
Use `MCUnreachable` instead of `MCAssert(false)`, and add a forced exit after it for Release mode (mode in which neither `MCUnreachable` / `MCAssert` have an action) Add `MCAssert(<condition>)` where an `else if (<condition)` statement has been replaced by an `else` statement
1 parent c6bd398 commit eddea6c

File tree

10 files changed

+41
-14
lines changed

10 files changed

+41
-14
lines changed

engine/src/combiners.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ template<Operation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32
402402
r = 0x00ffffff;
403403
break;
404404
default:
405-
MCAssert(false);
405+
MCUnreachable();
406+
// MCUnreachable has no action in Release mode
407+
return 0;
406408
}
407409

408410
if (x_src_alpha && x_dst_alpha)
@@ -534,7 +536,9 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t ari
534536
}
535537
break;
536538
default:
537-
MCAssert(false);
539+
MCUnreachable();
540+
// MCUnreachable has no action in Release mode
541+
return 0;
538542
}
539543

540544
if (x_src_alpha && x_dst_alpha)
@@ -648,7 +652,9 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t bas
648652
r = packed_multiply_bounded(src, packed_inverse(dst)) + dst;
649653
break;
650654
default:
651-
MCAssert(false);
655+
MCUnreachable();
656+
// MCUnreachable has no action in Release mode
657+
return 0;
652658
}
653659

654660
return r;
@@ -874,7 +880,9 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t adv
874880
t_alpha = t_src_alpha + t_dst_alpha - downscale(t_src_alpha_dst_alpha);
875881
break;
876882
default:
877-
MCAssert(false);
883+
MCUnreachable();
884+
// MCUnreachable has no action in Release mode
885+
return 0;
878886
}
879887

880888
if (x_dst_alpha)

engine/src/fieldrtf.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ static bool export_rtf_emit_paragraphs(void *p_context, MCFieldExportEventType p
484484
else if (t_list_style == kMCParagraphListStyleCircle)
485485
t_char = 0x25E6, t_marker = "circle";
486486
else // kMCParagraphListStyleNone
487+
{
488+
MCAssert(t_list_style == kMCParagraphListStyleNone);
487489
return false;
490+
}
488491
/* UNCHECKED */ MCStringAppendFormat(ctxt.m_text, "{\\listlevel\\levelnfc23\\leveljc0\\levelstartat1\\levelfollow0{\\*\\levelmarker \\{%s\\}}{\\leveltext\\'01\\u%d.;}{\\levelnumbers;}",
489492
t_marker, t_char);
490493
}

engine/src/mblandroiddialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ bool MCSystemPickDate(MCDateTime *p_current, MCDateTime *p_min, MCDateTime *p_ma
157157
bool t_use_min, t_use_max;
158158

159159
// Avoid to leave t_min/t_max uninitialised, even though showDatePicker
160-
// won't use it if t_use_min/t_use_max is not true
160+
// only use them if t_use_min/t_use_max is true
161161
t_min = 0;
162162
t_max = 0;
163163

engine/src/mblhandlers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,7 +3129,7 @@ Exec_stat MCHandleCancelLocalNotification(void *context, MCParameter *p_paramete
31293129
t_success = false;
31303130

31313131

3132-
if (!ctxt.HasError() && t_success)
3132+
if (t_success && ctxt.HasError())
31333133
return ES_NORMAL;
31343134

31353135
return ES_ERROR;
@@ -4429,7 +4429,7 @@ Exec_stat MCHandleUseDeviceResolution(void *context, MCParameter *p_parameters)
44294429
if (t_success)
44304430
MCMiscSetUseDeviceResolution(ctxt, t_use_device_res, t_use_control_device_res);
44314431

4432-
if (!ctxt.HasError() && t_success)
4432+
if (t_success && !ctxt.HasError())
44334433
return ES_NORMAL;
44344434

44354435
return ES_ERROR;

engine/src/mbliphonemail.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ static void compose_mail_prewait(void *p_context)
472472
t_data = [NSData dataWithMCDataRef: ctxt -> attachments[i] . data];
473473
else // ctxt -> attachments[i] . file != nil
474474
{
475+
MCAssert(ctxt -> attachments[i] . file != nil);
475476
MCAutoStringRef t_resolved_path;
476477
MCS_resolvepath(ctxt -> attachments[i] . file, &t_resolved_path);
477478
t_data = [[NSData alloc] initWithContentsOfMappedFile: [NSString stringWithMCStringRef: *t_resolved_path]];

engine/src/redraw.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ MCLayerModeHint MCControl::layer_computeattrs(bool p_commit)
212212
t_layer_mode = kMCLayerModeHintStatic;
213213
}
214214
else
215-
MCAssert(false);
215+
{
216+
MCUnreachable();
217+
// MCUnreachable has no action in Release mode. Return current value
218+
return m_layer_mode;
219+
}
216220

217221
// Now compute the sprite attribute.
218222
bool t_is_sprite;

engine/src/srvdebug.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ void MCServerDebugGet(MCStringRef p_property, MCStringRef& r_result)
443443
/* UNCHECKED */ MCeerror -> copyasstringref(t_error);
444444
else if (MCStringIsEqualToCString(p_property, "parse error", kMCCompareExact))
445445
MCperror -> copyasstringref(t_error);
446+
else if (MCStringIsEqualToCString(p_property, "files", kMCCompareExact))
447+
t_error = MCValueRetain(kMCEmptyString);
446448
else
447449
t_error = MCValueRetain(kMCEmptyString);
448450

libcore/src/module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bool MCModuleGetFilename(MCModuleRef p_module, char*& r_path)
163163
bool MCModuleLoad(const char *p_filename, MCModuleRef& r_module)
164164
{
165165
MCModuleRef t_module;
166-
t_module = NULL;
166+
t_module = nil;
167167
if (MCCStringEndsWith(p_filename, ".dylib"))
168168
{
169169
t_module = (void *)dlopen(p_filename, (RTLD_NOW | RTLD_LOCAL));
@@ -175,7 +175,7 @@ bool MCModuleLoad(const char *p_filename, MCModuleRef& r_module)
175175
CFURLRef t_url;
176176
t_url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)p_filename, MCCStringLength(p_filename), TRUE);
177177
if (t_url != nil)
178-
{
178+
{
179179
t_module = (void *)CFBundleCreate(kCFAllocatorDefault, t_url);
180180
if (t_module != nil)
181181
t_module = (void *)((uintptr_t)t_module | 1);

libgraphics/src/legacyblendmodes.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ template<Operation x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32
480480
r = 0x00ffffff;
481481
break;
482482
default:
483-
MCAssert(false);
483+
MCUnreachable();
484+
// MCUnreachable has no action in Release mode
485+
return 0;
484486
}
485487

486488
if (x_src_alpha && x_dst_alpha)
@@ -611,7 +613,9 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t ari
611613
}
612614
break;
613615
default:
614-
MCAssert(false);
616+
MCUnreachable();
617+
// MCUnreachable has no action in Release mode
618+
return 0;
615619
}
616620

617621
if (x_src_alpha && x_dst_alpha)
@@ -725,7 +729,9 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t bas
725729
r = packed_multiply_bounded(src, packed_inverse(dst)) + dst;
726730
break;
727731
default:
728-
MCAssert(false);
732+
MCUnreachable();
733+
// MCUnreachable has no action in Release mode
734+
return 0;
729735
}
730736

731737
return r;
@@ -951,7 +957,9 @@ template<int x_combiner, bool x_dst_alpha, bool x_src_alpha> INLINE uint32_t adv
951957
t_alpha = t_src_alpha + t_dst_alpha - downscale(t_src_alpha_dst_alpha);
952958
break;
953959
default:
954-
MCAssert(false);
960+
MCUnreachable();
961+
// MCUnreachable has no action in Release mode
962+
return 0;
955963
}
956964

957965
if (x_dst_alpha)

revbrowser/src/revbrowser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,7 @@ void XBrowserSetProp(char *args[], int nargs, char **retstring, Bool *pass, Bool
18141814
}
18151815
else // nargs == 2
18161816
{
1817+
MCAssert(nargs == 2);
18171818
t_browser = s_browsers . GetActiveInstance();
18181819
if (t_browser == NULL)
18191820
{

0 commit comments

Comments
 (0)