Skip to content

Commit

Permalink
Fix some compiler warnings (#289)
Browse files Browse the repository at this point in the history
* Fix comparison of non-dereferenced char* with '\0'

* Fix left-shifting of signed negative integers

It produced lots of compiler warnings on UB on code such as
MMC_IMMEDIATE(MMC_TAGFIXNUM(-1)) (and possibly other instances
of UB not detected by the compiler).
  • Loading branch information
atrosinenko authored and mahge committed Dec 17, 2019
1 parent c4ed8a9 commit 7b1cd62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions OMCompiler/SimulationRuntime/c/meta/meta_modelica_data.h
Expand Up @@ -138,15 +138,15 @@ typedef int mmc_switch_type;
#define MMC_TAGPTR(p) ((void*)((char*)(p) + 3))
#define MMC_UNTAGPTR(x) ((void*)((char*)(x) - 3))
#define MMC_IS_INTEGER(X) (0 == ((mmc_sint_t) (X) & 1))
#define MMC_TAGFIXNUM(i) (((i) << 1)+0)
#define MMC_TAGFIXNUM(i) ((((mmc_uint_t) (i)) << 1)+0)
#define MMC_UNTAGFIXNUM(X) (((mmc_sint_t) (X)) >> 1)

#else

#define MMC_TAGPTR(p) ((void*)((char*)(p) + 0))
#define MMC_UNTAGPTR(x) ((void*)((char*)(x) - 0))
#define MMC_IS_INTEGER(X) (1 == ((mmc_sint_t) (X) & 1))
#define MMC_TAGFIXNUM(i) (((i) << 1)+1)
#define MMC_TAGFIXNUM(i) ((((mmc_uint_t) (i)) << 1)+1)
#define MMC_UNTAGFIXNUM(X) (((mmc_sint_t) ((X)-1)) >> 1)

#endif
Expand Down
Expand Up @@ -110,7 +110,7 @@ static const char* skipValue(const char* str)
switch (*str) {
case '\0': fprintf(stderr, "Found end of file, expected end of string"); abort();
case '\\':
if (str+1 == '\0') {
if (*(str+1) == '\0') {
fprintf(stderr, "Found end of file, expected end of string"); abort();
}
str+=2;
Expand Down

0 comments on commit 7b1cd62

Please sign in to comment.