SV = NULL(0x0) at 0x22cfb41ffb0
REFCNT = 1
FLAGS = (PADTMP)
####
SV = PV(0x22cfb55afc8) at 0x22cfb43c068
REFCNT = 1
FLAGS = (PADTMP,POK,pPOK)
PV = 0x22cfd20c3d8 ""\0
CUR = 0
LEN = 10
##
##
use strict;
use warnings;
use Devel::Peek;
use Inline C =><<'EOC';
#include
#include
const char *
string_reverse(const char *input)
{
static char *output = NULL;
int i, len;
if(output != NULL) {
free(output);
printf("YES - output free()ed\n");
}
if(input == NULL)
return NULL;
len = strlen(input);
output = malloc(len+1);
for(i=0; input[i]; i++)
output[len-i-1] = input[i];
output[len] = '\0';
return output;
}
const char *
nullstr() {
return NULL;
}
EOC
print string_reverse("\nHello World");
Dump(string_reverse(undef));
Dump(nullstr());
__END__
Outputs:
dlroW olleH
Use of uninitialized value in subroutine entry at try.pl line 42.
YES - output free()ed
SV = PV(0x22b16cbafc8) at 0x22b16bdcba8
REFCNT = 1
FLAGS = (PADTMP,POK,pPOK)
PV = 0x22b19158598 ""\0
CUR = 0
LEN = 10
SV = NULL(0x0) at 0x22b16bbfed0
REFCNT = 1
FLAGS = (PADTMP)