LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   SIGSEGV segmentation fault at strftime_l lib64/libc.so.6 (https://www.linuxquestions.org/questions/linux-kernel-70/sigsegv-segmentation-fault-at-strftime_l-lib64-libc-so-6-a-945028/)

smilebhuff 05-15-2012 04:44 AM

SIGSEGV segmentation fault at strftime_l lib64/libc.so.6
 
I'am porting pro*c codes from UNIX to LINUX. The codes are compiled and created executables successfully. But during run time its raising segmentation fault. I debugged the code step by step and the below is the output of GDB debug.

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

Actually in code the function strftime() is called not strftime_l(). But I have no idea why it is reaching strftime_l in /lib64/libc.so.6.

This issue is not coming in UNIX. please help on this.

pan64 05-15-2012 05:21 AM

I think it is pretty obvious, see man strftime. strftime has an implicite default locale, otherwise both do the same thing (so strftime calls strftime_l with an additional argument)
The segfault can be caused by either the buffer is too small or by an illegal variable handling (so for example dummy_time points to nowhere)

smilebhuff 05-15-2012 06:13 AM

thanks for you reply. From my application code strftime() is called. But the segmentation fault is at strftime_l() .

Program received signal SIGSEGV, Segmentation fault. 0x0000003b19690f8b in strftime_l () from /lib64/libc.so.6

My first question is why its going to strftime_l() when am calling strftime() in code.

pan64 05-15-2012 06:18 AM

because strftime does nothing else just calls strftime_l passing all the original arguments and an additional one: the locale settings. The functionality is implemented in the function strftime_l.

smilebhuff 05-15-2012 06:22 AM

could please help me where to see the definition or implementation of strftime() ? I tried to check whether it calls strftime_l() but I couldn't get where this function implementation is seen?

pan64 05-15-2012 06:46 AM

(this is obvious). It is usual in the linux world: you can have a few similar functions with almost the same functionality. some of them has default values or assumes some settings. In such cases all those functions invoke the most general one passing their inputs and adding the assumed ones. The functionality is implemented only once and in this general version.

Since this is part of libc you need to download the source code of it and look into the code for the real implementation (there will be a strftime.c or similar). you can find it for example here: http://www.gnu.org/software/libc/download.html

smilebhuff 05-15-2012 08:35 AM

you are saying that strftime() calls strftime_l(). Is that on assumption or?

pan64 05-15-2012 08:44 AM

that is coming from your post. You told you wrote strftime, but you see strftime_l, and asked why. Either you called directly strftime_l or it is called from strftime. The "Single stepping until exit from function strftime" just walked into strftime_l and the code is died inside strftime_l.

smilebhuff 05-15-2012 09:24 AM

ok pan.. thanks for your instant replies.. modified code .. and it woked now!!


All times are GMT -5. The time now is 04:00 PM.