Skip to content

Commit

Permalink
dynamic_alloc: Replace implicit type conversion with incorrect semant…
Browse files Browse the repository at this point in the history
…ics by proper return value (microsoft#99)

The dynamic_alloc example fails to compile on Visual Studio 2015 due to an C4800 / C2220 compiler error (LONG status is used as return value). Apart from the performance warning, which is treated as error because of the /WX flag, the semantics of this operation seem to be wrong. At the end of the function, we find return status == NO_ERROR. That means that in line 70 a successful execution results in a return value of true and an unsuccessful execution results in false. However, if the function is left in line 52, the return code is true (because the test status != NO_ERROR was positive).

Fix this, and force /we4800 to be enabled to catch issues in the future. 

Co-authored-by: Brian Gianforcaro <[email protected]>
  • Loading branch information
michael-os and Brian Gianforcaro authored Aug 28, 2020
1 parent 25982e4 commit 9546ddb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion samples/common.mak
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CLIB=/MT
!ENDIF

AFLAGS=/nologo /Zi /c /Fl
CFLAGS=/nologo /Zi $(CLIB) /Gm- /W4 /WX /Od
CFLAGS=/nologo /Zi $(CLIB) /Gm- /W4 /WX /we4800 /Od

!IF $(DETOURS_SOURCE_BROWSING)==1
CFLAGS=$(CFLAGS) /FR
Expand Down
2 changes: 1 addition & 1 deletion samples/dynamic_alloc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool DetourTransaction(std::function<bool()> callback) {
LONG status = DetourTransactionBegin();
if (status != NO_ERROR) {
Log("DetourTransactionBegin failed with %08x\n", status);
return status;
return status == NO_ERROR;
}

if (callback()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DETOURS_SOURCE_BROWSING = 0

#######################/#######################################################
##
CFLAGS=/nologo /W4 /WX /Zi /MT /Gy /Gm- /Zl /Od
CFLAGS=/nologo /W4 /WX /we4800 /Zi /MT /Gy /Gm- /Zl /Od

!IF $(DETOURS_SOURCE_BROWSING)==1
CFLAGS=$(CFLAGS) /FR
Expand Down

0 comments on commit 9546ddb

Please sign in to comment.