Reviewed By: jvillard Differential Revision: D13450070 fbshipit-source-id: d6f53bacamaster
							parent
							
								
									6a59abd234
								
							
						
					
					
						commit
						5c4de212fb
					
				@ -0,0 +1,27 @@
 | 
				
			||||
/*
 | 
				
			||||
 * 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
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue