Merge pull request #11798 from keszybz/mem-sanitizer-fix

meson: make sure preprocesor warnings are not treated as errors
This commit is contained in:
Lennart Poettering 2019-02-25 13:50:56 +01:00 committed by GitHub
commit c55a447ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 17 deletions

View File

@ -333,6 +333,7 @@ possible_cc_flags = [
'-Wno-missing-field-initializers',
'-Wno-unused-result',
'-Wno-format-signedness',
'-Wno-error=#warnings',
# work-around for gcc 7.1 turning this on on its own.
'-Wno-error=nonnull',

View File

@ -8,6 +8,10 @@
#include "macro.h"
#if HAS_FEATURE_MEMORY_SANITIZER
# include <sanitizer/msan_interface.h>
#endif
typedef void (*free_func_t)(void *p);
/* If for some reason more than 4M are allocated on the stack, let's abort immediately. It's better than
@ -160,3 +164,9 @@ void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size);
(ptr) = NULL; \
_ptr_; \
})
#if HAS_FEATURE_MEMORY_SANITIZER
# define msan_unpoison(r, s) __msan_unpoison(r, s)
#else
# define msan_unpoison(r, s)
#endif

View File

@ -23,16 +23,13 @@
# include <linux/random.h>
#endif
#include "alloc-util.h"
#include "fd-util.h"
#include "io-util.h"
#include "missing.h"
#include "random-util.h"
#include "time-util.h"
#if HAS_FEATURE_MEMORY_SANITIZER
#include <sanitizer/msan_interface.h>
#endif
int rdrand(unsigned long *ret) {
#if defined(__i386__) || defined(__x86_64__)
@ -58,11 +55,7 @@ int rdrand(unsigned long *ret) {
"setc %1"
: "=r" (*ret),
"=qm" (err));
#if HAS_FEATURE_MEMORY_SANITIZER
__msan_unpoison(&err, sizeof(err));
#endif
msan_unpoison(&err, sizeof(err));
if (!err)
return -EAGAIN;

View File

@ -8,6 +8,7 @@
#include "json.h"
#include "string-util.h"
#include "strv.h"
#include "tests.h"
#include "util.h"
static void test_tokenizer(const char *data, ...) {
@ -391,6 +392,13 @@ static void test_depth(void) {
log_info("max depth at %u", i);
break;
}
#if HAS_FEATURE_MEMORY_SANITIZER
/* msan doesn't like the stack nesting to be too deep. Let's quit early. */
if (i >= 128) {
log_info("quitting early at depth %u", i);
break;
}
#endif
assert_se(r >= 0);
@ -403,10 +411,7 @@ static void test_depth(void) {
}
int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
log_parse_environment();
log_open();
test_setup_logging(LOG_DEBUG);
test_tokenizer("x", -EINVAL);
test_tokenizer("", JSON_TOKEN_END);

View File

@ -36,7 +36,7 @@ static void test_mount_propagation_flags(const char *name, int ret, unsigned lon
static void test_mnt_id(void) {
_cleanup_fclose_ FILE *f = NULL;
Hashmap *h;
_cleanup_hashmap_free_free_ Hashmap *h = NULL;
Iterator i;
char *p;
void *k;
@ -57,7 +57,14 @@ static void test_mnt_id(void) {
assert_se(r > 0);
assert_se(sscanf(line, "%i %*s %*s %*s %ms", &mnt_id, &path) == 2);
#if HAS_FEATURE_MEMORY_SANITIZER
/* We don't know the length of the string, so we need to unpoison it one char at a time */
for (const char *c = path; ;c++) {
msan_unpoison(c, 1);
if (!*c)
break;
}
#endif
log_debug("mountinfo: %s → %i", path, mnt_id);
assert_se(hashmap_put(h, INT_TO_PTR(mnt_id), path) >= 0);
@ -84,8 +91,6 @@ static void test_mnt_id(void) {
log_debug("the other path for mnt id %i is %s\n", mnt_id2, t);
assert_se(path_equal(p, t));
}
hashmap_free_free(h);
}
static void test_path_is_mount_point(void) {