aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/events.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel/src/events.c')
-rw-r--r--libcrystfel/src/events.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/libcrystfel/src/events.c b/libcrystfel/src/events.c
index 731f39f8..8d059528 100644
--- a/libcrystfel/src/events.c
+++ b/libcrystfel/src/events.c
@@ -34,6 +34,7 @@
#include <hdf5.h>
#include <string.h>
#include <stdlib.h>
+#include <assert.h>
struct event *initialize_event()
@@ -555,23 +556,27 @@ int pop_dim_entry_from_event(struct event *ev)
}
-char *event_path_placeholder_subst(const char *entry,
- const char *data)
+char *event_path_placeholder_subst(const char *entry, const char *data)
{
char *ph_loc;
char *full_path;
- int len_head, len_tail;
+ ptrdiff_t len_head;
+ size_t len_entry, len_data;
- full_path = malloc((strlen(data) + strlen(entry)+1)*sizeof(char));
- ph_loc = strstr(data, "%");
- len_head = ph_loc-data;
- len_tail = strlen(ph_loc);
+ len_entry = strlen(entry);
+ len_data = strlen(data);
+ full_path = malloc(len_data + len_entry + 1);
+ if ( full_path == NULL ) return NULL;
+
+ ph_loc = strchr(data, '%');
+ len_head = ph_loc - data;
+ assert(len_head >= 0);
strncpy(full_path, data, len_head);
- strncpy(full_path+len_head, entry, strlen(entry));
- strncpy(full_path+len_head+strlen(entry), ph_loc+1, len_tail);
- strncpy(&full_path[strlen(data) + strlen(entry)],"\0",1);
+ full_path[len_head] = '\0';
+ strcat(full_path, entry);
+ strcat(full_path, ph_loc+1);
return full_path;
}
@@ -586,13 +591,12 @@ char *retrieve_full_path(struct event *ev, const char *data)
for ( ei=0; ei<ev->path_length; ei++ ) {
- char *tmp_subst_data;
- tmp_subst_data = event_path_placeholder_subst(ev->path_entries[ei],
- return_value);
+ char *tmp;
+ tmp = event_path_placeholder_subst(ev->path_entries[ei],
+ return_value);
free(return_value);
- return_value = strdup(tmp_subst_data);
- free(tmp_subst_data);
+ return_value = tmp;
}