编译运行:
as run.s -o run.o
ld run.o -o run
./run
GDB调试也没问题
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from run...done.
(gdb) b _start
Breakpoint 1 at 0x400078: file run.s, line 6.
(gdb) r
Starting program: /home/×××××××/Desktop/run
Breakpoint 1, _start () at run.s:6
6movl $1, %eax
(gdb) ni
7movl $0, %ebx
(gdb) ni
8int $0x80
(gdb) ni
[Inferior 1 (process 10617) exited normally]
(gdb) b _start
简单看了一下你的程序首先,你没有给出完整的程序,这个让大伙看起来确实不方便,因为没有main函数,可能踩内存的地方并不是这个函数本身,是main函数
其次说你的这个函数,貌似确实有点问题,但是由于没有完整的程序,我只说出我的理解,如果有错,直接忽视就好
sprintf(flag_height,"%03d",i+1)
sprintf(flag_width,"%03d",j+1)
我觉得问题出在这里,你查下
sprintf
的用法,第一个参数应该是一个字符串的首地址,你写的确实没有错,参数给入的是一个地址flag_height,但是纵观你的程序,你并没有给这个指针赋值,程序运行到这里,估计在默认创建指针的时候应该赋值为NULL(貌似根据编译器不同而有不同),那个寻址后报出段错误,也是意料之中了
由于没有你完整的代码,不知道你要做什么,修改意见不好提
给出个人意见,仅供参考
如果要打印flag_height中的值,首先应该给flag_height指针分配一片内存,使用malloc函数,其次在向内从中写入值,然后调用sprintf,就应该没有问题了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)