aboutsummaryrefslogtreecommitdiff
path: root/graphics/sjis.cpp
diff options
context:
space:
mode:
authorD G Turner2013-12-15 08:17:57 +0000
committerD G Turner2014-01-15 02:36:19 +0000
commitac4087856f02725c288e1cef6b089acf7a6121aa (patch)
treebd74a9b82489f1f4e0dc72de84de7ed5f83c6a88 /graphics/sjis.cpp
parent74fbd2de82ebc255968b754ec91e005ab4123cdc (diff)
downloadscummvm-rg350-ac4087856f02725c288e1cef6b089acf7a6121aa.tar.gz
scummvm-rg350-ac4087856f02725c288e1cef6b089acf7a6121aa.tar.bz2
scummvm-rg350-ac4087856f02725c288e1cef6b089acf7a6121aa.zip
ALL: Remove optimization unstable code on checking for null after new.
These issues were identified by the STACK tool. By default, the C++ new operator will throw an exception on allocation failure, rather than returning a null pointer. The result is that testing the returned pointer for null is redundant and _may_ be removed by the compiler. This is thus optimization unstable and may result in incorrect behaviour at runtime. However, we do not use exceptions as they are not supported by all compilers and may be disabled. To make this stable without removing the null check, you could qualify the new operator call with std::nothrow to indicate that this should return a null, rather than throwing an exception. However, using (std::nothrow) was not desirable due to the Symbian toolchain lacking a <new> header. A global solution to this was also not easy by redefining "new" as "new (std::nothrow)" due to custom constructors in NDS toolchain and various common classes. Also, this would then need explicit checks for OOM adding to all new usages as per C malloc which is untidy. For now to remove this optimisation unstable code is best as it is likely to not be present anyway, and OOM will cause a system library exception instead, even without exceptions enabled in the application code.
Diffstat (limited to 'graphics/sjis.cpp')
-rw-r--r--graphics/sjis.cpp20
1 files changed, 7 insertions, 13 deletions
diff --git a/graphics/sjis.cpp b/graphics/sjis.cpp
index 33f0e562cb..59ee5af8c4 100644
--- a/graphics/sjis.cpp
+++ b/graphics/sjis.cpp
@@ -40,31 +40,25 @@ FontSJIS *FontSJIS::createFont(const Common::Platform platform) {
// Try the font ROM of the specified platform
if (platform == Common::kPlatformFMTowns) {
ret = new FontTowns();
- if (ret) {
- if (ret->loadData())
- return ret;
- }
+ if (ret->loadData())
+ return ret;
delete ret;
} else if (platform == Common::kPlatformPCEngine) {
ret = new FontPCEngine();
- if (ret) {
- if (ret->loadData())
- return ret;
- }
+ if (ret->loadData())
+ return ret;
delete ret;
} // TODO: PC98 font rom support
/* else if (platform == Common::kPlatformPC98) {
ret = new FontPC98();
- if (ret) {
- if (ret->loadData())
- return ret;
- }
+ if (ret->loadData())
+ return ret;
delete ret;
}*/
// Try ScummVM's font.
ret = new FontSjisSVM(platform);
- if (ret && ret->loadData())
+ if (ret->loadData())
return ret;
delete ret;