Обсуждение: OFFTOPIC: core dumped with strcpy,atoi,sprintf.

Поиск
Список
Период
Сортировка

OFFTOPIC: core dumped with strcpy,atoi,sprintf.

От
"Ing.Edmundo.Robles.Lopez"
Дата:
Hi.
I hope you can help me. I have problems with some functions like
strcpy, atoi, etc and  would like to know the correct list where I have
to ask this:



I have compiled a program  under SCO Openserver, and  run succesfully.
But when  i compile the same program in Ubuntu  12.04,  i got a core dump.


Debugging the program, found that the core is generated  by atoi,
sprintf and similar functions; because that functions fails when
received  a null pointer (NULL). But, if  the functions received  an
empty string ("") the program continues and run succesfully.


Yes,  I should validate each input pointers. But, its odd that works in
SCO and not in Linux, and its odder that fails in functions like strcpy,
atoi, sprintf, etc.


I have a lot of programs that i should compile in boths operative
systems. And if you kown something that can  help me, really, really i'd
appreciate.  :-)


Regards.
El contenido de este correo electrónico y sus archivos adjuntos son privados y confidenciales y va dirigido
exclusivamentea su destinatario.  No se autoriza la utilización, retransmisión, diseminación, o cualquier otro uso de
estainformación por un receptor o entidades distintas al destinatario.  Si recibe este correo sin ser el destinatario
sele solicita eliminarlo y hacerlo del conocimiento del emisor. La empresa no se hace responsable de transmisiones o
comunicacionesno autorizadas o emitidas por personas ajenas a sus colaboradores utilizando éste medio electrónico. 

The content of this email and its attached files are private and confidential and intended exclusively for the use of
theindividual or entity to which they are addressed. The retransmission, dissemination, or any other use of this
informationother than by the intended recipient is prohibited.  If you have received this email in error please delete
itand notify the sender.  The company cannot be held liable for unauthorized electronic transmissions or
communications,nor for those emitted by non-company individuals and entities. 


Re: OFFTOPIC: core dumped with strcpy,atoi,sprintf.

От
Tom Lane
Дата:
"Ing.Edmundo.Robles.Lopez" <erobles@sensacd.com.mx> writes:
> Debugging the program, found that the core is generated  by atoi,
> sprintf and similar functions; because that functions fails when
> received  a null pointer (NULL). But, if  the functions received  an
> empty string ("") the program continues and run succesfully.

> Yes,  I should validate each input pointers. But, its odd that works in
> SCO and not in Linux, and its odder that fails in functions like strcpy,
> atoi, sprintf, etc.

Not really.  Per the POSIX spec, the behavior of those functions is
undefined for NULL input pointers.  Some platforms are forgiving about
it, most are not.

            regards, tom lane


Re: OFFTOPIC: core dumped with strcpy,atoi,sprintf.

От
Scott Marlowe
Дата:
On Fri, Sep 14, 2012 at 10:37 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Ing.Edmundo.Robles.Lopez" <erobles@sensacd.com.mx> writes:
>> Debugging the program, found that the core is generated  by atoi,
>> sprintf and similar functions; because that functions fails when
>> received  a null pointer (NULL). But, if  the functions received  an
>> empty string ("") the program continues and run succesfully.
>
>> Yes,  I should validate each input pointers. But, its odd that works in
>> SCO and not in Linux, and its odder that fails in functions like strcpy,
>> atoi, sprintf, etc.
>
> Not really.  Per the POSIX spec, the behavior of those functions is
> undefined for NULL input pointers.  Some platforms are forgiving about
> it, most are not.

I learned C on a platform with no memory protection wherein a null
pointer would result in a write to location 0 and an immediate machine
crash.  Wow, that was a LONG time ago (late 80s).  Kids today.  Got it
easy.