17也不行
#include <stdio.h>
typedef unsigned char uint8_t;
int main(void)
{
uint8_t *a[17]; // 这里为什么是 17 呢?小于17的数都不行
printf("%d, %d, %d, %d\n", sizeof(a), sizeof(*a), sizeof(uint8_t), sizeof((uint8_t *)"00000000"));
*a = (uint8_t *)"00000000";
*(a + 8) = (uint8_t *)"11111111";
*(a + 16) = (uint8_t *)"22222222";
*(a + 24) = (uint8_t *)"33333333";
*(a + 32) = (uint8_t *)"44444444";
*(a + 40) = (uint8_t *)"55555555";
*(a + 48) = (uint8_t *)"66666666";
printf("%s\n", *a);
printf("%s\n", *(a + 8));
printf("%s\n", *(a + 16));
printf("%s\n", *(a + 24));
printf("%s\n", *(a + 32));
printf("%s\n", *(a + 40));
printf("%s\n", *(a + 48));
return 0;
}
1>------ 已启动全部重新生成: 项目: tmp, 配置: Debug Win32 ------
1>main.c
1>c:\visualstudioprojects\tmp\tmp\main.c(14): warning C4789: 缓冲区“a”(大小为 68 字节)将溢出;4 字节将在偏移 96 时开始写入
1>c:\visualstudioprojects\tmp\tmp\main.c(15): warning C4789: 缓冲区“a”(大小为 68 字节)将溢出;4 字节将在偏移 128 时开始写入
1>c:\visualstudioprojects\tmp\tmp\main.c(16): warning C4789: 缓冲区“a”(大小为 68 字节)将溢出;4 字节将在偏移 160 时开始写入
1>c:\visualstudioprojects\tmp\tmp\main.c(17): warning C4789: 缓冲区“a”(大小为 68 字节)将溢出;4 字节将在偏移 192 时开始写入
1>tmp.vcxproj -> C:\VisualStudioProjects\tmp\Debug\tmp.exe
1>已完成生成项目“tmp.vcxproj”的操作。
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
#include <stdio.h>
typedef unsigned char uint8_t;
int main(void)
{
uint8_t *a[49]; // *(a + 48) = (uint8_t *)"66666666"; 所以这里需要49个
printf("%d, %d, %d, %d\n", sizeof(a), sizeof(*a), sizeof(uint8_t), sizeof((uint8_t *)"00000000"));
*a = (uint8_t *)"00000000";
*(a + 8) = (uint8_t *)"11111111";
*(a + 16) = (uint8_t *)"22222222";
*(a + 24) = (uint8_t *)"33333333";
*(a + 32) = (uint8_t *)"44444444";
*(a + 40) = (uint8_t *)"55555555";
*(a + 48) = (uint8_t *)"66666666";
printf("%s\n", *a);
printf("%s\n", *(a + 8));
printf("%s\n", *(a + 16));
printf("%s\n", *(a + 24));
printf("%s\n", *(a + 32));
printf("%s\n", *(a + 40));
printf("%s\n", *(a + 48));
return 0;
}
1>------ 已启动全部重新生成: 项目: tmp, 配置: Debug Win32 ------
1>main.c
1>tmp.vcxproj -> C:\VisualStudioProjects\tmp\Debug\tmp.exe
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
|