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

Commit 8ae02d1

Browse files
committed
libfoundation: Add type checks to MCError functions.
1 parent 9ba076a commit 8ae02d1

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

libfoundation/src/foundation-error.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ MCErrorCreateWithMessage (MCTypeInfoRef p_typeinfo,
128128
MCArrayRef p_info,
129129
MCErrorRef & r_error)
130130
{
131+
__MCAssertIsErrorTypeInfo(p_typeinfo);
132+
__MCAssertIsString(p_message);
133+
if (nil != p_info)
134+
__MCAssertIsArray(p_info);
135+
131136
__MCError *self;
132137
if (!__MCValueCreate(kMCValueTypeCodeError, self))
133138
return false;
@@ -161,6 +166,7 @@ bool MCErrorCreate(MCTypeInfoRef p_typeinfo, MCArrayRef p_info, MCErrorRef& r_er
161166
MC_DLLEXPORT_DEF
162167
bool MCErrorUnwind(MCErrorRef p_error, MCValueRef p_target, uindex_t p_row, uindex_t p_column)
163168
{
169+
__MCAssertIsError(p_error);
164170
MCErrorFrame *t_frame;
165171
if (!MCMemoryNew(t_frame))
166172
return false;
@@ -186,24 +192,29 @@ bool MCErrorUnwind(MCErrorRef p_error, MCValueRef p_target, uindex_t p_row, uind
186192
MC_DLLEXPORT_DEF
187193
MCNameRef MCErrorGetDomain(MCErrorRef self)
188194
{
195+
__MCAssertIsError(self);
189196
return MCErrorTypeInfoGetDomain(self -> typeinfo);
190197
}
191198

192199
MC_DLLEXPORT_DEF
193200
MCArrayRef MCErrorGetInfo(MCErrorRef self)
194201
{
202+
__MCAssertIsError(self);
195203
return self -> info;
196204
}
197205

198206
MC_DLLEXPORT_DEF
199207
MCStringRef MCErrorGetMessage(MCErrorRef self)
200208
{
209+
__MCAssertIsError(self);
201210
return self -> message;
202211
}
203212

204213
MC_DLLEXPORT_DEF
205214
uindex_t MCErrorGetDepth(MCErrorRef self)
206215
{
216+
__MCAssertIsError(self);
217+
207218
if (self -> backtrace == nil)
208219
return 0;
209220

@@ -232,6 +243,8 @@ static MCErrorFrame *__MCErrorGetFrameAtLevel(MCErrorRef self, uindex_t p_level)
232243
MC_DLLEXPORT_DEF
233244
MCValueRef MCErrorGetTargetAtLevel(MCErrorRef self, uindex_t p_level)
234245
{
246+
__MCAssertIsError(self);
247+
235248
MCErrorFrame *t_frame;
236249
t_frame = __MCErrorGetFrameAtLevel(self, p_level);
237250
if (t_frame == nil)
@@ -243,6 +256,8 @@ MCValueRef MCErrorGetTargetAtLevel(MCErrorRef self, uindex_t p_level)
243256
MC_DLLEXPORT_DEF
244257
uindex_t MCErrorGetRowAtLevel(MCErrorRef self, uindex_t p_level)
245258
{
259+
__MCAssertIsError(self);
260+
246261
MCErrorFrame *t_frame;
247262
t_frame = __MCErrorGetFrameAtLevel(self, p_level);
248263
if (t_frame == nil)
@@ -254,6 +269,8 @@ uindex_t MCErrorGetRowAtLevel(MCErrorRef self, uindex_t p_level)
254269
MC_DLLEXPORT_DEF
255270
uindex_t MCErrorGetColumnAtLevel(MCErrorRef self, uindex_t p_level)
256271
{
272+
__MCAssertIsError(self);
273+
257274
MCErrorFrame *t_frame;
258275
t_frame = __MCErrorGetFrameAtLevel(self, p_level);
259276
if (t_frame == nil)
@@ -267,6 +284,8 @@ uindex_t MCErrorGetColumnAtLevel(MCErrorRef self, uindex_t p_level)
267284
MC_DLLEXPORT_DEF
268285
bool MCErrorThrow(MCErrorRef p_error)
269286
{
287+
__MCAssertIsError(p_error);
288+
270289
if (s_last_error != nil)
271290
MCValueRelease(s_last_error);
272291

@@ -306,6 +325,8 @@ MCErrorCreateAndThrowWithMessageV (MCTypeInfoRef p_error_type,
306325
MCStringRef p_message,
307326
va_list p_args)
308327
{
328+
__MCAssertIsErrorTypeInfo(p_error_type);
329+
__MCAssertIsString(p_message);
309330
MCAutoArrayRef t_info;
310331
if (!MCArrayCreateMutable(&t_info))
311332
return false;
@@ -393,18 +414,21 @@ bool MCErrorThrowOutOfMemory(void)
393414
MC_DLLEXPORT_DEF
394415
bool MCErrorThrowUnboundType(MCTypeInfoRef p_type)
395416
{
417+
__MCAssertIsTypeInfo(p_type);
396418
return MCErrorCreateAndThrow(kMCUnboundTypeErrorTypeInfo, "type", MCNamedTypeInfoGetName(p_type), nil);
397419
}
398420

399421
MC_DLLEXPORT_DEF
400422
bool MCErrorThrowUnimplemented(MCStringRef p_reason)
401423
{
424+
__MCAssertIsString(p_reason);
402425
return MCErrorCreateAndThrow(kMCUnimplementedErrorTypeInfo, "reason", p_reason, nil);
403426
}
404427

405428
MC_DLLEXPORT_DEF
406429
bool MCErrorThrowGeneric(MCStringRef p_reason)
407430
{
431+
__MCAssertIsString(p_reason);
408432
return MCErrorCreateAndThrow(kMCGenericErrorTypeInfo, "reason", p_reason, nil);
409433
}
410434

0 commit comments

Comments
 (0)