You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
766 B

/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <stdlib.h>
struct s {
int useless_field_because_flexible_array_members_are_not_allowed_in_otherwise_empty_struct;
int arr[];
};
void access_to_incomplete_array_type(struct s* a, int i) { a->arr[i] = 0; }
void call_access_to_incomplete_array_type_Good_FP() {
struct s* x = malloc(sizeof(struct s) + sizeof(int));
access_to_incomplete_array_type(x, 0);
}
void call_access_to_incomplete_array_type_Bad() {
struct s* x = malloc(sizeof(struct s) + sizeof(int));
access_to_incomplete_array_type(x, 1);
}
// For tests with last field of size 0 or 1, see class.cpp