Add gcc version check for diagnostic pragmas 59/221959/2
authorYunjin Lee <yunjin-.lee@samsung.com>
Wed, 8 Jan 2020 10:43:18 +0000 (19:43 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Thu, 9 Jan 2020 02:22:38 +0000 (11:22 +0900)
- Add gcc version check for diagnostics that are not supported at lower gcc version

Change-Id: I1f4c9160d475f395a7e61f03980580043c1a8e6d
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
capi/src/privilege_manager.c

index eaf6646efbd09dbb7330d2aab0ec101fb17f5036..4f89de1611f6f483b2176dcf588df897440fb36a 100755 (executable)
 #define _LOGI(fmt, arg...)
 #endif
 
-#pragma GCC diagnostic ignored "-Wstringop-truncation"
-#pragma GCC diagnostic ignored "-Wstringop-overflow"
+#ifdef __GNUC__
+#if __GNUC__ >= 8
+#define PUSH_IGNORE_STRING_WARNINGS \
+       _Pragma("GCC diagnostic push") \
+       _Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"") \
+       _Pragma("GCC diagnostic ignored \"-Wstringop-overflow\"")
+#define POP_IGNORE_STRING_WARNINGS _Pragma("GCC diagnostic pop")
+#else
+#define PUSH_IGNORE_STRING_WARNINGS
+#define POP_IGNORE_STRING_WARNINGS
+#endif
+#endif
 
 #define TryReturn(condition, expr, returnValue, ...)\
        if (!(condition)) { \
@@ -316,8 +326,10 @@ int privilege_manager_verify_privilege(uid_t uid, const char *api_version, privi
                        char *tmp_message_list = realloc(message_list, new_size);
                        TryReturn(tmp_message_list != NULL, ret_val = PRVMGR_ERR_OUT_OF_MEMORY; goto FINISH, PRVMGR_ERR_OUT_OF_MEMORY, "[PRVMGR_ERR_OUT_OF_MEMORY] message_list's realloc is failed.");
                        message_list = tmp_message_list;
+                       PUSH_IGNORE_STRING_WARNINGS
                        strncat(message_list, "[MISMATCHED_PRIVILEGE_LEVEL]|", strlen("[MISMATCHED_PRIVILEGE_LEVEL]|"));
                        strncat(message_list, mismatched_message, strlen(mismatched_message));
+                       POP_IGNORE_STRING_WARNINGS
                }
                size_t total_size = snprintf(0, 0, "%s%s", message_list, newline) + 1;
                char* tmp_message_list = realloc(message_list, total_size);