[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
swat ! String pointers & VarProbes
From: |
Sven Thommesen |
Subject: |
swat ! String pointers & VarProbes |
Date: |
Thu, 12 Dec 1996 10:18:35 -0600 |
Since I burdened the list with my recent core dump troubles,
I guess I'd better report that the problem has been solved.
And <blush, blush> it was all my fault!
Despite the way some C books make it look like character arrays
and character pointers are 'the same', they're not. If you define
char * X;
and then use sprintf(X,...) or strcpy(X,...) without first initalizing X to
point to a valid string, the results are ... a core dump, and one that gdb
is of
little help with, to boot.
And when K&R (2nd ed, p. 194) say that "the behavior of a program that
attempts to alter a string literal is undefined", they mean it. Undefined,
as in another core dump!
(That is, defining 'char * X = "SomeString" ' and then using sprintf or
strcpy with X as a target.)
My thanks to Glen for handholding.
We did, trying to track down this elusive bug, discover one interesting
thing about the VarProbe machinery: it works the opposite way of sprintf()
and strcpy() ! If you allocate an instance variable 'char X[80]' in your
program and try to use ObjectLoader to fill that variable from a disk file,
you get an error message. No can do. But if you define 'char * X' and leave
it un-initialized, the probe code will load your string into memory
somewhere and make X point to it. Go figure.
Hope this confessional was of marginal use to someone.
Now on to the next bug, wherever it may lurk!
Sven.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- swat ! String pointers & VarProbes,
Sven Thommesen <=