Operating System - HP-UX
1833784 Members
2398 Online
110063 Solutions
New Discussion

memcpy( ) behaviour on 11i HP-UX machine

 
Puneet_1
Occasional Contributor

memcpy( ) behaviour on 11i HP-UX machine

This is regarding the memcpy() function
used on HP-UX 11.11 machine. memcpy ()
takes 3 parameters. First two are
strings and third one is no. of bytes
to be copied. If we pass the third
argument a negative number I.e. number
of bytes to be copy is negative then it
works fine with HP-UX v10.2 and v11.0
but fails (give segmentation fault
core) on 11i HP-UX machine.

Why is this scenario?
3 REPLIES 3
Adam J Markiewicz
Trusted Contributor

Re: memcpy( ) behaviour on 11i HP-UX machine

???

How would you define 'working fine while copying negative number of bytes'? This function should do something exept from returning without core.

Actually I belive that core gewnerating is 'working fine with such argument' (to be precise - I assume you're not trying to copy more that 2 GB of memory), so the previous behaviour is simply a bug.

Regards

Adam
I do everything perfectly, except from my mistakes
Puneet_1
Occasional Contributor

Re: memcpy( ) behaviour on 11i HP-UX machine

Actually the scenario is like this:

My program logic calls memcpy funtion:
call memcpy(char *str1, char *str2, int count);

As per the logic of the program this count equal to -1. Which logically should not be the case. But we diidn't come across any problem when we ran our program on HP-UX 10.2 and HP-UX 11.0. But hen we ported it to HP-UX 11.11, our program generated a core. On debugging we found out that actually program logic is trying to copy negative byte using memcpy and while doing so it is generating core.
Then we prepared a small program which simply uses memcpy function. We found out that in HP-UX 10.2 and HP-UX 11.0, whenever memcpy acounter its third argument negative it treats it as zero. But in 11.11 HP -UX it genrated segmentation fault core dump.

I want to know that is this a bug or is it an enhancement of HP-UX 11.11 machine.

Is there a patch available for this or do I have to provide a check before memcpy() function that throw an error when ever third argument (no. of bytes to cpopy) is negative.

Let me know in case of any doubts.

Thanks and regards.
Adam J Markiewicz
Trusted Contributor

Re: memcpy( ) behaviour on 11i HP-UX machine

from /usr/inclue/string.h:
extern void *memcpy(void *, const void *, size_t);

from: /usr/include/sys/_size_t.h:
typedef unsigned long size_t;

If you are interested in how much bytes are you trying to copy use:
printf( "Number of bytes: %lu\n", (unsigned long) -1L );

Why did it work before? I don't know, but I think it shouldn't also.

Hope this exhaust your doubts. :)

Adam
I do everything perfectly, except from my mistakes