linux – strftime_l lib64libc.so.6中的SIGSEGV分段错误

linux – strftime_l lib64libc.so.6中的SIGSEGV分段错误,第1张

概述我将pro * c代码从UNIX移植到LINUX.代码被成功编译和创建可执行文件.但在运行时它的提升分段错误.我一步一步地调试了代码,下面是GDB调试的输出. Breakpoint 4 at 0x3b19690f50 (gdb) n 525 strftime (buf, MAX_STRING_LEN, "%d/%b/%Y:%H:%M:%S", dummy_time); 我将pro * c代码从UNIX移植到liNUX.代码被成功编译和创建可执行文件.但在运行时它的提升分段错误.我一步一步地调试了代码,下面是GDB调试的输出.

Breakpoint 4 at 0x3b19690f50 (gdb) n 525             strftime (buf,MAX_STRING_LEN,"%d/%b/%Y:%H:%M:%s",dummy_time); (gdb) n Breakpoint 4,0x0000003b19690f50 in strftime () from /lib64/libc.so.6 (gdb) n Single stepPing until exit from function strftime,which has no line number information. 0x0000003b19690f70 in strftime_l () from /lib64/libc.so.6 (gdb) n Single stepPing until exit from function strftime_l,which has no line number information. Program received signal SIGSEGV,Segmentation fault. 0x0000003b19690f8b in strftime_l () from /lib64/libc.so.6

实际上在代码中调用函数strftime().但我不知道为什么它会在/lib64/libc.so.6中到达strftime_l().

这个问题不会出现在UNIX中.请帮忙.代码是

static voID speed_Hack_libs(voID){    time_t dummy_time_t = time(NulL);    struct tm *dummy_time = localtime (&dummy_time_t);    struct tm *other_dummy_time = gmtime (&dummy_time_t);    char buf[MAX_STRING_LEN];    strftime (buf,dummy_time);}
解决方法
struct tm *dummy_time = localtime (&dummy_time_t);struct tm *other_dummy_time = gmtime (&dummy_time_t);

这不会奏效.从man page:

@H_404_31@

The localtime() function converts the calendar time timep to broken-down time representation,expressed relative to the user’s specifIEd time-zone. … The return value points to a statically allocated struct which might be overwritten by
subsequent calls to any of the date and time functions.

The gmtime() function converts the calendar time timep to broken-down time representation,expressed in Coordinated Universal Time (UTC). It
may return NulL when the year does not fit into an integer. The return value points to a statically allocated struct which might be overwritten by subsequent calls to any of the date and time functions.

因此,* dummy_time可能会在您使用它时被覆盖,并包含不可预测的垃圾.您应该将数据复制到缓冲区,如下所示:

struct tm dummy_time ;memcpy(&dummy_time,localtime (&dummy_time_t),sizeof(struct tm));

虽然我不确定这怎么会导致SIGSEGV(可能是获得月份名称等等 – 检查问题是否仍然存在于LC_ALL = C),你必须先解决这个问题才能继续.另外,检查(在调试器中)* dummy_time的内容.

总结

以上是内存溢出为你收集整理的linux – strftime_l lib64 / libc.so.6中的SIGSEGV分段错误全部内容,希望文章能够帮你解决linux – strftime_l lib64 / libc.so.6中的SIGSEGV分段错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1025042.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存