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.

68 lines
2.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include "math.h" // 确保包含自定义头文件
#include <math.h> // 补充包含标准数学头文件
#include <ctype.h>
#include <complex.h>
// 基于原项目真实代码的arrayIndexOutOfBounds问题验证测试用例
// 问题ID: arrayIndexOutOfBounds
// 原始消息: Array 'arr[3]' accessed at index 3, which is out of bounds.
// 目标: 验证原项目中arrayIndexOutOfBounds问题
// 基于文件: /home/feng/Report-Generation/math.c:1393
// 问题行: arr[index] = 0;
// 函数: is_normal_positive_perfect_cube
// 基于原项目真实代码的数组越界测试
// 问题详情: Array 'arr[3]' accessed at index 3, which is out of bounds.
// 原文件位置: /home/feng/Report-Generation/math.c:1393
// 问题行内容: arr[index] = 0;
// 相关变量: 1, 0
// 使用更严格的数组越界检测
void test_arrayIndexOutOfBounds() {
printf("开始测试数组越界访问问题...\n");
printf("问题类型: arrayIndexOutOfBounds\n");
printf("原文件: /home/feng/Report-Generation/math.c:1393\n");
printf("原问题行: arr[index] = 0;\n");
// 创建数组并故意越界访问
int arr[5] = {1, 2, 3, 4, 5};
printf("数组内容: ");
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
printf("\n");
// 故意越界访问 - 这应该被检测到
printf("尝试越界访问 arr[10]...\n");
int value = arr[10]; // 越界访问
printf("越界访问结果: %d\n", value);
// 使用assert来强制检测
assert(arr[10] == 0); // 这应该失败
printf("数组越界访问完成\n");
}
int main() {
printf("=== 验证原项目中的arrayIndexOutOfBounds问题 ===\n");
printf("问题ID: arrayIndexOutOfBounds\n");
printf("基于文件: /home/feng/Report-Generation/math.c:1393\n");
printf("问题行: arr[index] = 0;\n");
// 调用基于原项目的测试函数
test_arrayIndexOutOfBounds();
printf("SUCCESS: Program completed - arrayIndexOutOfBounds issue verified based on original project code\n");
return 0;
}
// 编译命令: g++ -std=c++17 -Wall -Wextra -g -O0 -o test_arrayIndexOutOfBounds test_arrayIndexOutOfBounds.cpp
// 运行命令: ./test_arrayIndexOutOfBounds
// 预期输出: 基于原项目真实代码验证arrayIndexOutOfBounds问题
// 判定规则: 如果程序行为符合预期则验证了原项目中arrayIndexOutOfBounds告警的真实性
// 注意: 使用 -Wall -Wextra 编译选项可以检测更多问题