Skip to content

Commit

Permalink
Fix ptr-comparison-to-string-literal error
Browse files Browse the repository at this point in the history
A new error raised in the latest versions of gcc and clang.

The address of string literals is undefined in the C standard so the
compiler raises an error if one tries to test for string equality by
comparing them. A better fix would be to replace QOF_ID strings with an
int-based identifier; an even better one would get rid of QOF_ID
entirely and use the C++ type system.
  • Loading branch information
jralls committed Sep 25, 2020
1 parent d642397 commit 1c55617
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions libgnucash/engine/qofid.h
Expand Up @@ -96,27 +96,7 @@ typedef struct QofCollection_s QofCollection;
#define QOF_ID_BOOK "Book"
#define QOF_ID_SESSION "Session"

/** Inline string comparison; compiler will optimize away most of this */
#ifndef _MSC_VER
# define QSTRCMP(da,db) ({ \
gint val = 0; \
if ((da) && (db)) { \
if ((da) != (db)) { \
val = strcmp ((da), (db)); \
} \
} else \
if ((!(da)) && (db)) { \
val = -1; \
} else \
if ((da) && (!(db))) { \
val = 1; \
} \
val; /* block assumes value of last statement */ \
})
#else
/* MSVC: Simply use g_strcmp */
# define QSTRCMP g_strcmp0
#endif
#define QSTRCMP g_strcmp0

/** return TRUE if object is of the given type */
#define QOF_CHECK_TYPE(obj,type) (((obj) != NULL) && \
Expand Down

0 comments on commit 1c55617

Please sign in to comment.