#!/bin/sh

set -x

cd $(mktemp -d)

cat > a.c <<EOF
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <dmalloc.h>

int main(void)
{
  static const char *s = "1234567";

  char *p = strndup(s,4);
  printf("%s\n", p);

  return 0;
}
EOF

# these all work
gcc                     a.c -ldmalloc && ./a.out
gcc -O2                 a.c -ldmalloc && ./a.out
gcc -D_GNU_SOURCE=1     a.c -ldmalloc && ./a.out
# this fails
gcc -D_GNU_SOURCE=1 -O2 a.c -ldmalloc && ./a.out

# dump the preprocessor output
# gcc -D_GNU_SOURCE=1 -O2 a.c -E > a.i
