#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
#include <argz.h>

int main(void)
{
    size_t len;
    char *buff1 = malloc(100);
    char *buff2 = "zhangtao";

    memset(buff1,'s',10);
    argz_add(&buff1,&(strlen(buff1)),buff2);

    printf("%s %d %s \n",__func__,__LINE__,buff1);

    free(buff1);
	return 0;
}

编译结果如下所示

错误原因:

因为函数的返回值存储在eax寄存器中,所以不可以直接操作,需要将其mov到内存中才可以操作。所有的函数都一样,不可以直接取地址。

修改如下所示:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
#include <argz.h>

int main(void)
{
    size_t len;
    char *buff1 = malloc(100);
    char *buff2 = "zhangtao";

    memset(buff1,'s',10);
    len = strlen(buff1);
    argz_add(&buff1,&(len),buff2);

    printf("%s %d %s \n",__func__,__LINE__,buff1);

    free(buff1);
	return 0;
}

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐