diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-09-23 18:01:42 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-09-23 18:01:42 +0000 |
commit | 246c8f01a79961423b23bd61650f66a72932d27e (patch) | |
tree | 171545999731f616af1ea6ff6767c5170f306def /src/triplet.c | |
parent | 5e889958688b0ae315a93f4230f2e9a71a9095e9 (diff) | |
download | wydawca-246c8f01a79961423b23bd61650f66a72932d27e.tar.gz wydawca-246c8f01a79961423b23bd61650f66a72932d27e.tar.bz2 |
* src/verify.c: Add a fixme comment
* src/triplet.c (triplet_processor): First check the state of a
triplet. Call verify_directive file only if it is
triplet_directive or triplet_complete
(expand_triplet_full,expand_triplet_upload): Fix coredump if one
of components is missing.
git-svn-id: file:///svnroot/wydawca/trunk@321 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src/triplet.c')
-rw-r--r-- | src/triplet.c | 98 |
1 files changed, 65 insertions, 33 deletions
diff --git a/src/triplet.c b/src/triplet.c index 0385fd0..e7bab3e 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -191,32 +191,36 @@ triplet_processor (void *data, void *proc_data) SP (trp->file[file_signature].name), SP (trp->file[file_directive].name)); - if (verify_directive_file (trp, dpair) == 0) + switch (check_triplet_state (trp)) { - switch (check_triplet_state (trp)) + case triplet_directive: + case triplet_complete: + if (debug_level) + logmsg (LOG_DEBUG, "Processing triplet `%s'", trp->name); + if (verify_directive_file (trp, dpair) == 0) { - case triplet_directive: - case triplet_complete: - if (debug_level) - logmsg (LOG_DEBUG, "Processing triplet `%s'", trp->name); process_directives (trp, dpair); return true; - - case triplet_incomplete: - if (debug_level) - logmsg (LOG_DEBUG, "%s: incomplete triplet", trp->name); - /* ignore unless expired (see below); */ - UPDATE_STATS (STAT_INCOMPLETE_TRIPLETS); - break; - - case triplet_bad: + } + else + { UPDATE_STATS (STAT_BAD_TRIPLETS); remove_triplet (trp); - return true; } + break; + + case triplet_incomplete: + if (debug_level) + logmsg (LOG_DEBUG, "%s: incomplete triplet", trp->name); + /* ignore unless expired (see below); */ + UPDATE_STATS (STAT_INCOMPLETE_TRIPLETS); + break; + + case triplet_bad: + UPDATE_STATS (STAT_BAD_TRIPLETS); + remove_triplet (trp); + return true; } - else - UPDATE_STATS (STAT_INCOMPLETE_TRIPLETS); if (triplet_expired_p (trp, dpair->file_sweep_time)) { @@ -371,17 +375,33 @@ expand_triplet_full (struct kw_expansion *exp, void *data) { struct file_triplet *trp = data; char *buf[FILE_TYPE_COUNT] = { NULL, NULL, NULL }; - - format_file_data (trp, file_dist, &buf[file_dist]); - format_file_data (trp, file_signature, &buf[file_signature]); - format_file_data (trp, file_directive, &buf[file_directive]); - - exp->value = xmalloc (strlen (buf[file_dist]) + 1 - + strlen (buf[file_signature]) + 1 - + strlen (buf[file_directive]) + 1); - sprintf (exp->value, "%s\n%s\n%s", buf[file_dist], buf[file_signature], - buf[file_directive]); + size_t size = 0; + if (format_file_data (trp, file_dist, &buf[file_dist]) == 0) + size += strlen (buf[file_dist]) + 1; + if (format_file_data (trp, file_signature, &buf[file_signature]) == 0) + size += strlen (buf[file_signature]) + 1; + if (format_file_data (trp, file_directive, &buf[file_directive]) == 0) + size += strlen (buf[file_directive]) + 1; + + exp->value = xmalloc (size + 1); + exp->value[0] = 0; + if (buf[file_dist]) + { + strcat(exp->value, buf[file_dist]); + strcat(exp->value, "\n"); + } + if (buf[file_signature]) + { + strcat(exp->value, buf[file_signature]); + strcat(exp->value, "\n"); + } + if (buf[file_directive]) + { + strcat(exp->value, buf[file_directive]); + strcat(exp->value, "\n"); + } + exp->value[size-1] = 0; /* Kill terminating newline */ free (buf[file_dist]); free (buf[file_signature]); free (buf[file_directive]); @@ -395,13 +415,25 @@ expand_triplet_upload (struct kw_expansion *exp, void *data) { struct file_triplet *trp = data; char *buf[2] = { NULL, NULL }; + size_t size = 0; - format_file_data (trp, file_dist, &buf[file_dist]); - format_file_data (trp, file_signature, &buf[file_signature]); + if (format_file_data (trp, file_dist, &buf[file_dist]) == 0) + size += strlen (buf[file_dist]) + 1; + if (format_file_data (trp, file_signature, &buf[file_signature]) == 0) + size += strlen (buf[file_signature]) + 1; - exp->value = xmalloc (strlen (buf[file_dist]) + 1 - + strlen (buf[file_signature]) + 1); - sprintf (exp->value, "%s\n%s", buf[file_dist], buf[file_signature]); + exp->value = xmalloc (size + 1); + if (buf[file_dist]) + { + strcat(exp->value, buf[file_dist]); + strcat(exp->value, "\n"); + } + if (buf[file_signature]) + { + strcat(exp->value, buf[file_signature]); + strcat(exp->value, "\n"); + } + exp->value[size-1] = 0; /* Kill terminating newline */ free (buf[file_dist]); free (buf[file_signature]); |