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

Commit 4cb170a

Browse files
committed
Turn on -Werror=unreachable-code
1 parent 51e6ff7 commit 4cb170a

File tree

10 files changed

+138
-151
lines changed

10 files changed

+138
-151
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ Function names:
146146
* Whenever adding a function, add a comment that explains precisely:
147147
* What the function does, under what conditions it succeeds, and how it behaves when it fails
148148
* What the function expects as inputs, and what outputs it generates
149+
* When disabling code with a false condition, prefix the condition with
150+
`/* DISABLES CODE */`. For example:
151+
152+
````
153+
if (/* DISABLES CODE */ (false))
154+
{
155+
/* <body> */
156+
}
157+
````
149158

150159
#### Layout and style
151160

config/mac.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
'-Werror=missing-field-initializers',
137137
'-Werror=objc-literal-compare',
138138
'-Werror=shadow',
139+
'-Werror=unreachable-code',
139140
],
140141
},
141142
},

engine/src/customprinter.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -144,38 +144,37 @@ bool MCCustomPrinterImageFromMCGImage(MCGImageRef p_image, MCCustomPrinterImage
144144

145145
void *t_pixel_cache;
146146
t_pixel_cache = nil;
147-
148-
if (kMCCustomPrinterImagePixelFormat == kMCGPixelFormatNative)
149-
t_pixels = t_raster.pixels;
150-
else
151-
{
152-
if (!MCMemoryAllocate(t_raster.stride * t_raster.height, t_pixel_cache))
153-
return false;
154-
155-
uint8_t *t_src;
156-
t_src = (uint8_t*)t_raster.pixels;
157-
158-
uint8_t *t_dst;
159-
t_dst = (uint8_t*)t_pixel_cache;
160-
161-
for (uint32_t i = 0; i < t_raster.height; i++)
162-
{
163-
uint32_t *t_src_row;
164-
t_src_row = (uint32_t*)t_src;
165-
166-
uint32_t *t_dst_row;
167-
t_dst_row = (uint32_t*)t_dst;
168-
169-
for (uint32_t j = 0; j < t_raster.width; j++)
170-
*t_dst_row++ = MCGPixelFromNative(kMCCustomPrinterImagePixelFormat, *t_src_row++);
171-
172-
t_src += t_raster.stride;
173-
t_dst += t_raster.stride;
174-
}
147+
148+
#if kMCCustomPrinterImagePixelFormat == kMCGPixelFormatNative
149+
t_pixels = t_raster.pixels;
150+
#else
151+
if (!MCMemoryAllocate(t_raster.stride * t_raster.height, t_pixel_cache))
152+
return false;
153+
154+
uint8_t *t_src;
155+
t_src = (uint8_t*)t_raster.pixels;
156+
157+
uint8_t *t_dst;
158+
t_dst = (uint8_t*)t_pixel_cache;
159+
160+
for (uint32_t i = 0; i < t_raster.height; i++)
161+
{
162+
uint32_t *t_src_row;
163+
t_src_row = (uint32_t*)t_src;
164+
165+
uint32_t *t_dst_row;
166+
t_dst_row = (uint32_t*)t_dst;
167+
168+
for (uint32_t j = 0; j < t_raster.width; j++)
169+
*t_dst_row++ = MCGPixelFromNative(kMCCustomPrinterImagePixelFormat, *t_src_row++);
175170

176-
t_pixels = t_pixel_cache;
177-
}
178-
171+
t_src += t_raster.stride;
172+
t_dst += t_raster.stride;
173+
}
174+
175+
t_pixels = t_pixel_cache;
176+
#endif
177+
179178
// Fill in the printer image info
180179
r_image.width = t_raster.width;
181180
r_image.height = t_raster.height;

engine/src/exec-multimedia.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ void MCMultimediaEvalSound(MCExecContext& ctxt, MCStringRef& r_sound)
295295
return;
296296
}
297297
#endif
298-
299-
ctxt . Throw();
300298
}
301299

302300
////////////////////////////////////////////////////////////////////////////////

engine/src/exec-pasteboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ MCTransferType MCPasteboardFindTransferTypeForLegacyClipboard(const MCClipboard*
279279
// passed that the behaviour can now be corrected but, until then, it is
280280
// disabled and the "text over images" method is used instead.
281281
//
282-
if (false)
282+
if (/* DISABLES CODE */ (false))
283283
{
284284
// If we have both an image and text on the clipboard, whichever one comes
285285
// first determines what we resolve the clipboard type to be.

engine/src/mac-theme.mm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@
129129
return s_system_font;
130130
}
131131
}
132-
133-
if (r_name)
134-
*r_name = nil;
135-
return nil;
136132
}
137133

138134

engine/src/opensslsocket.cpp

Lines changed: 94 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,98 @@ void MCS_secure_socket(MCSocket *s, Boolean sslverify, MCNameRef end_hostname)
11531153

11541154
bool MCS_hostaddress(MCStringRef &r_host_address)
11551155
{
1156+
#if defined(_MACOSX)
1157+
bool t_success;
1158+
t_success = true;
1159+
1160+
SCDynamicStoreRef t_store;
1161+
t_store = NULL;
1162+
if (t_success)
1163+
{
1164+
t_store = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("JSEvaluator"), NULL, NULL);
1165+
if (t_store == NULL)
1166+
t_success = false;
1167+
}
1168+
1169+
CFStringRef t_network_key;
1170+
t_network_key = NULL;
1171+
if (t_success)
1172+
{
1173+
t_network_key = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetIPv4);
1174+
if (t_network_key == NULL)
1175+
t_success = false;
1176+
}
1177+
1178+
CFDictionaryRef t_network_value;
1179+
t_network_value = NULL;
1180+
if (t_success)
1181+
{
1182+
t_network_value = (CFDictionaryRef)SCDynamicStoreCopyValue(t_store, t_network_key);
1183+
if (t_network_value == NULL)
1184+
t_success = false;
1185+
}
1186+
1187+
CFStringRef t_interface;
1188+
t_interface = NULL;
1189+
if (t_success)
1190+
{
1191+
t_interface = (CFStringRef)CFDictionaryGetValue(t_network_value, kSCDynamicStorePropNetPrimaryInterface);
1192+
if (t_interface == NULL)
1193+
t_success = false;
1194+
}
1195+
1196+
CFStringRef t_interface_key;
1197+
t_interface_key = NULL;
1198+
if (t_success)
1199+
{
1200+
t_interface_key = (CFStringRef)SCDynamicStoreKeyCreateNetworkInterfaceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, t_interface, kSCEntNetIPv4);
1201+
if (t_interface_key == NULL)
1202+
t_success = false;
1203+
}
1204+
1205+
CFDictionaryRef t_interface_value;
1206+
t_interface_value = NULL;
1207+
if (t_success)
1208+
{
1209+
t_interface_value = (CFDictionaryRef)SCDynamicStoreCopyValue(t_store, t_interface_key);
1210+
if (t_interface_value == NULL)
1211+
t_success = false;
1212+
}
1213+
1214+
char *t_result;
1215+
t_result = NULL;
1216+
if (t_success)
1217+
{
1218+
CFArrayRef t_addresses;
1219+
t_addresses = (CFArrayRef)CFDictionaryGetValue(t_interface_value, CFSTR("Addresses"));
1220+
if (t_addresses != NULL)
1221+
{
1222+
CFStringRef t_string;
1223+
t_string = (CFStringRef)CFArrayGetValueAtIndex(t_addresses, 0);
1224+
if (t_string != NULL)
1225+
t_result = osx_cfstring_to_cstring(t_string, false, false);
1226+
}
1227+
}
1228+
1229+
if (t_interface_value != NULL)
1230+
CFRelease(t_interface_value);
1231+
1232+
if (t_interface_key != NULL)
1233+
CFRelease(t_interface_key);
1234+
1235+
if (t_network_value != NULL)
1236+
CFRelease(t_network_value);
1237+
1238+
if (t_network_key != NULL)
1239+
CFRelease(t_network_key);
1240+
1241+
if (t_store != NULL)
1242+
CFRelease(t_store);
1243+
1244+
return MCStringCreateWithCString(t_result, r_host_address);
1245+
1246+
#else
1247+
11561248
#if defined(_WINDOWS)
11571249
if (!wsainit())
11581250
return NULL;
@@ -1174,102 +1266,13 @@ bool MCS_hostaddress(MCStringRef &r_host_address)
11741266
}
11751267
}
11761268
}
1177-
#elif defined(_MACOSX)
1178-
bool t_success;
1179-
t_success = true;
11801269

1181-
SCDynamicStoreRef t_store;
1182-
t_store = NULL;
1183-
if (t_success)
1184-
{
1185-
t_store = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("JSEvaluator"), NULL, NULL);
1186-
if (t_store == NULL)
1187-
t_success = false;
1188-
}
1189-
1190-
CFStringRef t_network_key;
1191-
t_network_key = NULL;
1192-
if (t_success)
1193-
{
1194-
t_network_key = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetIPv4);
1195-
if (t_network_key == NULL)
1196-
t_success = false;
1197-
}
1198-
1199-
CFDictionaryRef t_network_value;
1200-
t_network_value = NULL;
1201-
if (t_success)
1202-
{
1203-
t_network_value = (CFDictionaryRef)SCDynamicStoreCopyValue(t_store, t_network_key);
1204-
if (t_network_value == NULL)
1205-
t_success = false;
1206-
}
1207-
1208-
CFStringRef t_interface;
1209-
t_interface = NULL;
1210-
if (t_success)
1211-
{
1212-
t_interface = (CFStringRef)CFDictionaryGetValue(t_network_value, kSCDynamicStorePropNetPrimaryInterface);
1213-
if (t_interface == NULL)
1214-
t_success = false;
1215-
}
1216-
1217-
CFStringRef t_interface_key;
1218-
t_interface_key = NULL;
1219-
if (t_success)
1220-
{
1221-
t_interface_key = (CFStringRef)SCDynamicStoreKeyCreateNetworkInterfaceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, t_interface, kSCEntNetIPv4);
1222-
if (t_interface_key == NULL)
1223-
t_success = false;
1224-
}
1225-
1226-
CFDictionaryRef t_interface_value;
1227-
t_interface_value = NULL;
1228-
if (t_success)
1229-
{
1230-
t_interface_value = (CFDictionaryRef)SCDynamicStoreCopyValue(t_store, t_interface_key);
1231-
if (t_interface_value == NULL)
1232-
t_success = false;
1233-
}
1234-
1235-
char *t_result;
1236-
t_result = NULL;
1237-
if (t_success)
1238-
{
1239-
CFArrayRef t_addresses;
1240-
t_addresses = (CFArrayRef)CFDictionaryGetValue(t_interface_value, CFSTR("Addresses"));
1241-
if (t_addresses != NULL)
1242-
{
1243-
CFStringRef t_string;
1244-
t_string = (CFStringRef)CFArrayGetValueAtIndex(t_addresses, 0);
1245-
if (t_string != NULL)
1246-
t_result = osx_cfstring_to_cstring(t_string, false, false);
1247-
}
1248-
}
1249-
1250-
if (t_interface_value != NULL)
1251-
CFRelease(t_interface_value);
1252-
1253-
if (t_interface_key != NULL)
1254-
CFRelease(t_interface_key);
1255-
1256-
if (t_network_value != NULL)
1257-
CFRelease(t_network_value);
1258-
1259-
if (t_network_key != NULL)
1260-
CFRelease(t_network_key);
1261-
1262-
if (t_store != NULL)
1263-
CFRelease(t_store);
1264-
1265-
return MCStringCreateWithCString(t_result, r_host_address);
1266-
1267-
#elif defined(_LINUX)
1268-
#else
12691270
#endif
12701271

12711272
r_host_address = MCValueRetain(kMCEmptyString);
12721273
return true;
1274+
1275+
#endif
12731276
}
12741277

12751278
////////////////////////////////////////////////////////////////////////////////

engine/src/stack3.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,6 @@ IO_stat MCStack::load_stack(IO_handle stream, uint32_t version)
516516
return IO_NORMAL;
517517
}
518518
}
519-
520-
// IM-2013-09-30: [[ FullscreenMode ]] ensure old_rect is initialized for fullscreen stacks
521-
old_rect = rect;
522-
523-
return IO_NORMAL;
524519
}
525520

526521
IO_stat MCStack::extendedsave(MCObjectOutputStream& p_stream, uint4 p_part, uint32_t p_version)

libscript/src/module-arithmetic.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,8 @@ extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalNumberPlusNumber(MCNumberRef p_
158158
MCNumberCreateWithReal(MCNumberFetchAsReal(p_right), t_number);
159159
MCArithmeticExecAddNumberToNumber(p_left, t_number);
160160

161-
//if no error
162161
r_output = t_number;
163162
return;
164-
165-
//else
166-
MCValueRelease(t_number);
167163
}
168164

169165
extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalIntegerMinusInteger(integer_t p_left, integer_t p_right, integer_t& r_output)
@@ -188,12 +184,8 @@ extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalNumberMinusNumber(MCNumberRef p
188184
MCNumberCreateWithReal(MCNumberFetchAsReal(p_left), t_number);
189185
MCArithmeticExecSubtractNumberFromNumber(p_right, t_number);
190186

191-
//if no error
192187
r_output = t_number;
193188
return;
194-
195-
//else
196-
MCValueRelease(t_number);
197189
}
198190

199191
extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalIntegerTimesInteger(integer_t p_left, integer_t p_right, integer_t& r_output)
@@ -218,12 +210,8 @@ extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalNumberTimesNumber(MCNumberRef p
218210
MCNumberCreateWithReal(MCNumberFetchAsReal(p_right), t_number);
219211
MCArithmeticExecMultiplyNumberByNumber(t_number, p_left);
220212

221-
//if no error
222213
r_output = t_number;
223214
return;
224-
225-
//else
226-
MCValueRelease(t_number);
227215
}
228216

229217
extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalIntegerOverInteger(integer_t p_left, integer_t p_right, integer_t& r_output)
@@ -248,12 +236,8 @@ extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalNumberOverNumber(MCNumberRef p_
248236
MCNumberCreateWithReal(MCNumberFetchAsReal(p_left), t_number);
249237
MCArithmeticExecDivideNumberByNumber(t_number, p_right);
250238

251-
//if no error
252239
r_output = t_number;
253240
return;
254-
255-
//else
256-
MCValueRelease(t_number);
257241
}
258242

259243
extern "C" MC_DLLEXPORT_DEF void MCArithmeticEvalIntegerModInteger(integer_t p_left, integer_t p_right, integer_t& r_output)

0 commit comments

Comments
 (0)