view gcc/testsuite/c-c++-common/nonnull-2.c @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 04ced10e8804
children 1830386684a0
line wrap: on
line source

/* Test for the bad usage of "nonnull" function attribute parms.  */
/* { dg-do compile } */
/* { dg-options "-Wnonnull-compare" } */

void bar (char **);

__attribute__((nonnull (1, 3))) int
foo (char *cp1, char *cp2, char *cp3, char *cp4)
{
  if (cp1 == (char *) 0) /* { dg-warning "nonnull argument" "cp1 compared to NULL" } */
    return 1;

  cp1 = cp2;
  if (cp1 == (char *) 0) /* { dg-bogus "nonnull argument" } */
    return 2;

  if (!cp4)	   /* { dg-bogus "nonnull argument" } */
    return 3;

  char **p = &cp3;
  bar (p);
  if (cp3 == (char *) 0) /* { dg-bogus "nonnull argument" } */
    return 4;

  return 5;
}