鱼C论坛

 找回密码
 立即注册
查看: 5871|回复: 1

[已解决]使用strfry函数的返回值报错Segmentation fault

[复制链接]
发表于 2021-4-28 20:18:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define _GNU_SOURCE
  4. #define SOURCE_BUF_SIZE  16

  5. int main(){
  6.   char source[SOURCE_BUF_SIZE] = "1234567890";
  7.   char *dest = NULL;
  8.   dest = (char *) strfry (source);
  9.   //printf ("dest == %p\n", dest);
  10.   //printf ("dest == %s\n", dest);
  11.         for(int a = 0;;a++){
  12.                 if(*(dest+a) != '\0'){
  13.                         putchar(*(dest+a));
  14.                 }else{
  15.                         break;
  16.                 }
  17.         }
  18.   return 0;
  19. }
复制代码

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)
谢谢
最佳答案
2021-4-28 20:27:19
这个代码,我这边没问题

  1. #include <stdio.h>

  2. #define __USE_GNU
  3. #include <string.h>

  4. #define SOURCE_BUF_SIZE  16

  5. int main(){
  6.   char source[SOURCE_BUF_SIZE] = "1234567890";
  7.   char *dest = NULL;
  8.   dest = (char *) strfry (source);
  9.   //printf ("dest == %p\n", dest);
  10.   //printf ("dest == %s\n", dest);
  11.         for(int a = 0;;a++){
  12.                 if(*(dest+a) != '\0'){
  13.                         putchar(*(dest+a));
  14.                 }else{
  15.                         break;
  16.                 }
  17.         }
  18.   return 0;
  19. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-4-28 20:27:19 | 显示全部楼层    本楼为最佳答案   
这个代码,我这边没问题

  1. #include <stdio.h>

  2. #define __USE_GNU
  3. #include <string.h>

  4. #define SOURCE_BUF_SIZE  16

  5. int main(){
  6.   char source[SOURCE_BUF_SIZE] = "1234567890";
  7.   char *dest = NULL;
  8.   dest = (char *) strfry (source);
  9.   //printf ("dest == %p\n", dest);
  10.   //printf ("dest == %s\n", dest);
  11.         for(int a = 0;;a++){
  12.                 if(*(dest+a) != '\0'){
  13.                         putchar(*(dest+a));
  14.                 }else{
  15.                         break;
  16.                 }
  17.         }
  18.   return 0;
  19. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 00:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表