gpt4 book ai didi

c - memset 没有设置 num 个字节?

转载 作者:太空宇宙 更新时间:2023-11-04 06:36:18 26 4
gpt4 key购买 nike

在下面的简单程序中,命令指向堆上的 400 字节。然后我将“./search '”复制到命令中,*buffer 指向“'”(单引号)之后的下一个字节。启动缓冲区指向的内存,我使用 memset 将 300 个字节设置为值 0x41(ASCII“A”),然后附加结束单引号。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

int main(int argc, char *argv[]) {
char *command = (char *)malloc(400);
bzero(command, 400);

strcpy(command, "./search \'");
char *buffer = command + strlen(command);

memset(buffer, 0x41, 300);
strcat(command, "\'");

system(command);
free(command);
}

但是当我在 gdb 中查看 *command 和 *buffer 时,这就是我所看到的。

char * command 0x601010 "./search '", 'A' <repeats 186 times>...
char * buffer 0x60101e 'A' <repeats 200 times>...

首先我希望它说重复 299 次,其次我希望命令和缓冲区重复具有相似的值。有人可以告诉我我错过了什么吗?

最佳答案

来自GDB manual, section 10.8 Print Settings :

set print elements number-of-elements

Set a limit on how many elements of an array gdb will print. If gdb is printing a large array, it stops printing after it has printed the number of elements set by the set print elements command. This limit also applies to the display of strings. When gdb starts, this limit is set to 200. Setting number-of-elements to zero means that the printing is unlimited.

关于c - memset 没有设置 num 个字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14675293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com