summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--RPM4/src/RPM4.xs11
-rw-r--r--RPM4/t/02header.t4
2 files changed, 10 insertions, 5 deletions
diff --git a/RPM4/src/RPM4.xs b/RPM4/src/RPM4.xs
index 257e563..f03fdc0 100644
--- a/RPM4/src/RPM4.xs
+++ b/RPM4/src/RPM4.xs
@@ -995,14 +995,19 @@ Header_string(h, no_header_magic = 0)
PREINIT:
char * string = NULL;
int offset = 8; /* header magic length */
- void * ptr = NULL;
+ char * ptr = NULL;
int hsize = 0;
PPCODE:
hsize = headerSizeof(h, no_header_magic ? HEADER_MAGIC_NO : HEADER_MAGIC_YES);
string = headerUnload(h);
- ptr = string + (no_header_magic ? offset : 0);
- XPUSHs(sv_2mortal(newSVpv((char *)ptr, hsize)));
+ if (! no_header_magic) {
+ ptr = malloc(hsize);
+ memcpy(ptr, header_magic, 8);
+ memcpy(ptr + 8, string, hsize - 8);
+ }
+ XPUSHs(sv_2mortal(newSVpv(ptr ? ptr : string, hsize)));
free(string);
+ free(ptr);
int
Header_removetag(h, sv_tag)
diff --git a/RPM4/t/02header.t b/RPM4/t/02header.t
index b6ff323..52934e0 100644
--- a/RPM4/t/02header.t
+++ b/RPM4/t/02header.t
@@ -86,7 +86,7 @@ ok($string, "can get header as string");
my $hdl = File::Temp->new(UNLINK => 1);
print $hdl $string;
seek($hdl, 0, 0);
-my $hdr2 = RPM4::stream2header($hdl);
-isa_ok($hdr, "RPM4::Header", "can reparse header from a string");
+my $hdr2 = RPM4::stream2header($hdl, $magic);
+isa_ok($hdr2, "RPM4::Header", "can reparse header from a string");
}
}