2015-03-03 03:34:27 +08:00
|
|
|
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
|
2016-12-07 06:02:21 +08:00
|
|
|
// RUN: %clangxx_msan -O0 -g -DPOSITIVE %s -o %t && not %run %t 2>&1 | FileCheck %s
|
2013-11-28 22:14:48 +08:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <iconv.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
iconv_t cd = iconv_open("ASCII", "ASCII");
|
|
|
|
assert(cd != (iconv_t)-1);
|
|
|
|
|
|
|
|
char inbuf_[100];
|
|
|
|
strcpy(inbuf_, "sample text");
|
|
|
|
char outbuf_[100];
|
Adding Msan support to FreeBSD
Summary:
Enabling the memory sanitizer support for FreeBSD, most of unit tests are compatible.
- Adding fstat and stressor_r interceptors.
- Updating the struct link_map access since most likely the struct Obj_Entry had been updated since.
- Disabling few unit tests until further work is needed (or we can assume it can work in real world code).
Patch by: David CARLIER
Reviewers: vitalybuka, krytarowski
Reviewed By: vitalybuka
Subscribers: eugenis, dim, srhines, emaste, kubamracek, mgorny, fedor.sergeev, hintonda, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43080
llvm-svn: 326644
2018-03-03 19:43:11 +08:00
|
|
|
#if defined(__NetBSD__)
|
2017-12-09 08:41:59 +08:00
|
|
|
// Some OSes expect the 2nd argument of iconv(3) to be of type const char **
|
2015-04-25 19:07:05 +08:00
|
|
|
const char *inbuf = inbuf_;
|
|
|
|
#else
|
2013-11-28 22:14:48 +08:00
|
|
|
char *inbuf = inbuf_;
|
2015-04-25 19:07:05 +08:00
|
|
|
#endif
|
2013-11-28 22:14:48 +08:00
|
|
|
char *outbuf = outbuf_;
|
|
|
|
size_t inbytesleft = strlen(inbuf_);
|
|
|
|
size_t outbytesleft = sizeof(outbuf_);
|
|
|
|
|
|
|
|
#ifdef POSITIVE
|
|
|
|
{
|
|
|
|
char u;
|
|
|
|
char *volatile p = &u;
|
|
|
|
inbuf_[5] = *p;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
size_t res;
|
|
|
|
res = iconv(cd, 0, 0, 0, 0);
|
|
|
|
assert(res != (size_t)-1);
|
|
|
|
|
|
|
|
res = iconv(cd, 0, 0, &outbuf, &outbytesleft);
|
|
|
|
assert(res != (size_t)-1);
|
|
|
|
|
|
|
|
res = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
|
|
|
|
// CHECK: MemorySanitizer: use-of-uninitialized-value
|
|
|
|
// CHECK: #0 {{.*}} in main {{.*}}iconv.cc:[[@LINE-2]]
|
|
|
|
assert(res != (size_t)-1);
|
|
|
|
assert(inbytesleft == 0);
|
|
|
|
|
|
|
|
assert(memcmp(inbuf_, outbuf_, strlen(inbuf_)) == 0);
|
|
|
|
|
|
|
|
iconv_close(cd);
|
|
|
|
return 0;
|
|
|
|
}
|