simple code to illustrate the problem:
Code: Select all
#include <stddef>
#include <stdlib>
#include <stdio>
#include <string>
void subroutine(void);
int main(int argc, char **argv)
{
subroutine();
return 0;
}
void subroutine(void)
{
char *temp,
*temp2,
value[512 + 1];
strcpy(value, "abcdefghijklmnopqrstuvwxyz");
temp = value;
printf ("\n value = %s", value);
printf ("\n temp = %s", temp);
temp2 = malloc(512 + 1);
memset(temp2, 0, 512 + 1);
printf ("\n temp2 = %s", temp2);
return;
}
[End of file]
Code: Select all
$ r problem/nodeb
value = abcdefghijklmnopqrstuvwxyz
temp = abcdefghijklmnopqrstuvwxyz
temp2 =
$
debug session:
Code: Select all
4438: void subroutine(void)
4439: {
4440:
4441: char *temp,
4442: *temp2,
4443: value[512 + 1];
4444:
4445:
4446:
4447: strcpy(value, "abcdefghijklmnopqrstuvwxyz");
4448: temp = value;
4449:
->4450: printf ("\n value = %s", value);
4451: printf ("\n temp = %s", temp);
4452:
4453: temp2 = malloc(512 + 1);
4454: memset(temp2, 0, 512 + 1);
4455:
4456: printf ("\n temp2 = %s", temp2);
4457:
4458: return;
─ OUT -output─────────────────────────────────────────────────────────────────────────────────
break at routine PROBLEM\main
break at routine PROBLEM\subroutine
stepped to PROBLEM\subroutine\%LINE 4438+11
stepped to PROBLEM\subroutine\%LINE 4447
stepped to PROBLEM\subroutine\%LINE 4448
stepped to PROBLEM\subroutine\%LINE 4450
PROBLEM\subroutine\value: "abcdefghijklmnopqrstuvwxyz"
PROBLEM\subroutine\temp: 8848580204684932775
──────────────────────────────────────────────────────────────────────────────────────
─ PROMPT -error-program-prompt─────────────────────────────────────────────────────────────────────────────────
DBG> ex value
DBG> ex temp
DBG> ex *temp
%DEBUG-E-NOTRAZERO, Unable to find a trailing zero for ASCIZ object at address 7ACC78D07ACC76A7
DBG>
─────────────────────────────────────────────────────────────────────────────────────
temp S/B pointing at value - and from the output without debug, we know it is.
The debugger is totally lost.
We know the memory allocated to temp2 is set to all zeros (NULL) and we get the same error about being unable to find a trailing zero...
makes it difficult, when even local variables are not able to be examined, to do debugging....