The purpose of this program is to determine if a number between 1 and 1000 is prime by testing its divisibility with the first 11 prime integers. The program functions properly with most inputs. However, when I input an integer such as 468, stack smashing is detected. What is stack smashing and how do I resolve the issue?
I've tried researching stack smashing but I can't find specific examples that relate to my program. I am unaware of alternative methods …
所以我有一个有5个参数的方法.正如预期的那样,寄存器在调用之前就说明了:
$rdi: The receiver
$rsi: the selector for the method
$rdx: first arg
$rcx: second arg
$r8: third arg
$r9: fourth arg
$r10 fifth arg
Run Code Online (Sandbox Code Playgroud)
在该方法中,它首先要做的是调用另一个objective-c方法
这反过来调用objc_msgSend(见偏移+58):
MyApp`-[GTMOAuth2WindowController webView:resource:willSendRequest:redirectResponse:fromDataSource:]:
0x10044a1a0 <+0>: pushq %rbp
0x10044a1a1 <+1>: movq %rsp, %rbp
0x10044a1a4 <+4>: subq $0x40, %rsp
0x10044a1a8 <+8>: movq 0x10(%rbp), %rax
0x10044a1ac <+12>: movq %rdi, -0x10(%rbp)
0x10044a1b0 <+16>: movq %rsi, -0x18(%rbp)
0x10044a1b4 <+20>: movq %rdx, -0x20(%rbp)
0x10044a1b8 <+24>: movq %rcx, -0x28(%rbp)
0x10044a1bc <+28>: movq %r8, -0x30(%rbp)
0x10044a1c0 <+32>: movq %r9, -0x38(%rbp) …Run Code Online (Sandbox Code Playgroud) 我观察过堆栈粉碎并阅读了有关它的帖子,就像这个Stack smashing检测到的那样.我明白它就像我们试图超越边界一样,而gcc也有预防机制.但在我的情况下,当我更改行索引以跨越边界时,其打印值为0,但是当列索引超出边界时,它会导致堆栈粉碎.
以下是包含必要评论的计划
#include<stdio.h>
void main()
{
int i,j;
i=0;
j=0;
int d[2][2]={{0,0},{0,0}};
for(i=0;i<2;i++) //**when I put i<=2 there is no stack smashing**
{
for(j=0;j<2;j++) //**When I put j<=2 there comes the stack smashing**
{
if(i==j)
{
d[i][j]=1;
}
else
{
d[i][j]=0;
}
printf("%d ",d[i][j]);
}
printf("\n");
}
}
Run Code Online (Sandbox Code Playgroud)
矩阵$ ./a.out输出(i <= 2)和(j <2)
1 0
0 1
0 0
Run Code Online (Sandbox Code Playgroud)
输出(i <= 2)和(j <= 2)矩阵$ ./a.out
1 0 0
0 1 0
0 0 1
Run Code Online (Sandbox Code Playgroud)
*堆栈粉碎检测到*:./a.out终止中止(核心转储)
是否有任何固有的限制可以超过导致基于架构的堆栈粉碎的项目数量.或者这只是随机的?任何解释都会有所帮助,因为我无法想象
我正在使用C编程并使用gcc进行编译.每次我编译我得到一个堆栈粉碎检测到错误.这是什么意思,我该如何解决?
#include <stdio.h>
#define MAX_ARRAY 50
static int getScore(int assignmentNum[], int weight[], int daysLate[], float score[]){
int position, tempWeight, tempLate;
float tempScore;
scanf("%d %f %d %d", &position, &tempScore, &tempWeight, &tempLate);
score[position] = tempScore;
weight[position] = tempWeight;
daysLate[position] = tempLate;
assignmentNum[position] = position;
return weight[position];
}
int main(void){
int penalty_points, num_drop, num_assignment;
static int assignmentNum[MAX_ARRAY], daysLate[MAX_ARRAY], weight[MAX_ARRAY];
static float score[MAX_ARRAY];
char statGen;
int total = 0;
scanf("%d %d %s", &penalty_points, &num_drop, &statGen);
printf("%d\n", penalty_points);
while (total < 100) {
total = …Run Code Online (Sandbox Code Playgroud)