citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 7bcd4ee085b2763e4c39e6f2e3bfa9eac9dafc11
parent cf9674eedd45e3d88eae105c3ea459407672d57a
Author: kyle <kyle@0x30.net>
Date:   Mon, 16 Jan 2017 22:45:37 -0700

lib: reduce .data size in instrumented binaries

Diffstat:
Mlib.c | 7++++---
Mlib.h | 9+++++----
Mt/mem.pm | 2+-
3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib.c b/lib.c @@ -95,9 +95,10 @@ citrun_node_add(unsigned int major, unsigned int minor, struct citrun_node *n) /* Copy these fields from incoming node verbatim. */ new->size = n->size; - strncpy(new->comp_file_path, n->comp_file_path, 1024); - strncpy(new->abs_file_path, n->abs_file_path, 1024); - new->comp_file_path[1023] = new->abs_file_path[1023] = '\0'; + strncpy(new->comp_file_path, n->comp_file_path, CITRUN_PATH_MAX); + strncpy(new->abs_file_path, n->abs_file_path, CITRUN_PATH_MAX); + new->comp_file_path[CITRUN_PATH_MAX - 1] = '\0'; + new->abs_file_path[CITRUN_PATH_MAX - 1] = '\0'; /* Set incoming nodes data pointer to allocated space after struct. */ n->data = (unsigned long long *)(new + 1); diff --git a/lib.h b/lib.h @@ -1,5 +1,6 @@ -static const unsigned int citrun_major = 0; -static const unsigned int citrun_minor = 0; +#define CITRUN_PATH_MAX 256 +static const unsigned int citrun_major = 0; +static const unsigned int citrun_minor = 0; struct citrun_header { char magic[4]; @@ -15,8 +16,8 @@ struct citrun_header { struct citrun_node { unsigned int size; - char comp_file_path[1024]; - char abs_file_path[1024]; + char comp_file_path[CITRUN_PATH_MAX]; + char abs_file_path[CITRUN_PATH_MAX]; unsigned long long *data; }; diff --git a/t/mem.pm b/t/mem.pm @@ -37,7 +37,7 @@ sub new { while ($node_start < $self->{size}) { # Struct field ordering controlled by lib.h. my $data = substr($self->{mem}, $node_start, $node_fixed_size); - my @struct_fields = unpack("IZ1024Z1024", $data); + my @struct_fields = unpack("IZ256Z256", $data); # Store a hash of information we just found. my $buf_size = $struct_fields[0];