brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · eeeff9a Raw
63 lines · cpp
1// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t2// RUN: %clangxx_msan -O0 -g -DPOSITIVE %s -o %t && not %run %t 2>&1 | FileCheck %s3 4#include <assert.h>5#include <iconv.h>6#include <stdlib.h>7#include <string.h>8#include <stdio.h>9#include <errno.h>10 11#if defined(__NetBSD__)12#include <sys/param.h>13#if __NetBSD_Prereq__(9,99,17)14#define NETBSD_POSIX_ICONV 115#else16#define NETBSD_POSIX_ICONV 017#endif18#endif19 20int main(void) {21  iconv_t cd = iconv_open("ASCII", "ASCII");22  assert(cd != (iconv_t)-1);23 24  char inbuf_[100];25  strcpy(inbuf_, "sample text");26  char outbuf_[100];27#if defined(__NetBSD__) && !NETBSD_POSIX_ICONV28  // Some OSes expect the 2nd argument of iconv(3) to be of type const char **29  const char *inbuf = inbuf_;30#else31  char *inbuf = inbuf_;32#endif33  char *outbuf = outbuf_;34  size_t inbytesleft = strlen(inbuf_);35  size_t outbytesleft = sizeof(outbuf_);36 37#ifdef POSITIVE38  {39    char u;40    char *volatile p = &u;41    inbuf_[5] = *p;42  }43#endif44 45  size_t res;46  res = iconv(cd, 0, 0, 0, 0);47  assert(res != (size_t)-1);48 49  res = iconv(cd, 0, 0, &outbuf, &outbytesleft);50  assert(res != (size_t)-1);51 52  res = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);53  // CHECK: MemorySanitizer: use-of-uninitialized-value54  // CHECK: #0 {{.*}} in main {{.*}}iconv.cpp:[[@LINE-2]]55  assert(res != (size_t)-1);56  assert(inbytesleft == 0);57 58  assert(memcmp(inbuf_, outbuf_, strlen(inbuf_)) == 0);59 60  iconv_close(cd);61  return 0;62}63