Operating System - HP-UX
1755744 Members
2452 Online
108837 Solutions
New Discussion юеВ

Re: Extra Arguments under Workshop Debugger

 
kenneth_20
Occasional Contributor

Extra Arguments under Workshop Debugger

I'm running WorkShop 6 on a Solaris 8 system. I have a few questions regarding
the debugger. Given the following trival C program

#include
#include

int main() {

char X[10] = "test1";
char Y[10];

memcpy(Y,X,0x40000);
printf("Y=%s\n",Y);
}

When I run this under the debugger I get a SEGV with the following output:

main()
__align_cpy_1(0xffbefff0, 0xffbefffa, 0x3f9c8, 0x7, 0x3f9c0, 0xffbef9b8)

I have a couple of questions/comments on this:

1) I'm assuming __align_cpy_1 is a subroutine of memcpy (right?).
2) Where are there 6 arguments to this when memcpy only takes 3? I'm
asking because we have an actual customer problem that, when run under
WorkShop, shows the SEGV to occur on _memcpy itself, but there are still
6 rather than 3 arguments. Where are these extra 3 arguments coming
from?
3) From experiments, the 3rd argument, 0x3f9c8, is, as expected, the
length. However, shouldn't it be 0x40000?
2 REPLIES 2
Gregory Fruth
Esteemed Contributor

Re: Extra Arguments under Workshop Debugger

I don't know what "Workshop" is or what it has
to do with HP-UX, but your use of memcpy()
is a little strange. You're copying 256 kb from
X to Y, but X is only 10 bytes long. Y will
get the value "test1" and the contents of
memory following Y will get corrupted. It may
in fact corrupt X itself, because X may follow
Y in memory. Depending on the memory
layout of your OS it may also trash the
program stack, which could cause the
error messge you are seeing.

memcpy() is typically used for copying
arbitrary binary data, not strings. The
copy would be better implemented using
strncpy(), which will stop after it hits the
null byte at the end of X or if there's not
enough space in Y to receive the contents.

As for __align_cpy_1, it's probably a subroutine
in libc or perhaps in the kernel. _memcpy
is not the same as memcpy(); it's probably
a subroutine in libc as well. (System libraries
like libc usually employ a leading underscore
on internal subroutine names and internal
variables, which is why you should avoid
using a leading underscore in user-defined
subroutine or variable names.)

At any rate, memcpy() probably calls
_memcpy and/or __align_cpy_1 and
automatically supplies the 6 arguments
as needed. These may include the 3
arguments you passed to memcpy(), but
you cannot depend on any relationship
between the two sets.

Unless you you suspect there's a bug
in your vendor's libc or unless you are
really interested in its inner workings,
you probably shouldn't worry about the
arguments memcpy() passes to its
subroutines.

HTH
kenneth_20
Occasional Contributor

Re: Extra Arguments under Workshop Debugger

Sorry, please ignore this post.
This was meant for the Solaris
newsgroup (I'm juggling too many
platforms lately).