commit 1330f43034c3240b442d66c6b4cff52d7d2d42ff
Author: Oswald Buddenhagen <[email protected]>
Date: Sun Nov 13 22:19:40 2016 +0100
null-terminate lines read from state file & journal
makes the subsequent code less convoluted.
src/sync.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/sync.c b/src/sync.c
index 851d61b..11f49d1 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -734,10 +734,11 @@ load_state( sync_vars_t *svars )
gothdr:
while (fgets( buf, sizeof(buf), jfp )) {
line++;
- if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
+ if (!(t = strlen( buf )) || buf[--t] != '\n') {
error( "Error: incomplete sync state entry at
%s:%d\n", svars->dname, line );
goto jbail;
}
+ buf[t] = 0;
fbuf[0] = 0;
if (sscanf( buf, "%d %d %15s", &t1, &t2, fbuf ) < 2) {
error( "Error: invalid sync state entry at
%s:%d\n", svars->dname, line );
@@ -779,25 +780,27 @@ load_state( sync_vars_t *svars )
goto jbail;
if (!stat( svars->nname, &st ) && fgets( buf, sizeof(buf), jfp
)) {
debug( "recovering journal ...\n" );
- if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
+ if (!(t = strlen( buf )) || buf[--t] != '\n') {
error( "Error: incomplete journal header in
%s\n", svars->jname );
goto jbail;
}
- if (!equals( buf, t, JOURNAL_VERSION "\n",
strlen(JOURNAL_VERSION) + 1 )) {
+ buf[t] = 0;
+ if (!equals( buf, t, JOURNAL_VERSION,
strlen(JOURNAL_VERSION) )) {
error( "Error: incompatible journal version "
- "(got %.*s, expected "
JOURNAL_VERSION ")\n", t - 1, buf );
+ "(got %s, expected "
JOURNAL_VERSION ")\n", buf );
goto jbail;
}
srec = 0;
line = 1;
while (fgets( buf, sizeof(buf), jfp )) {
line++;
- if (!(t = strlen( buf )) || buf[t - 1] != '\n')
{
+ if (!(t = strlen( buf )) || buf[--t] != '\n') {
error( "Error: incomplete journal entry
at %s:%d\n", svars->jname, line );
goto jbail;
}
+ buf[t] = 0;
if ((c = buf[0]) == '#' ?
- (t3 = 0, (sscanf( buf + 2, "%d %d %n",
&t1, &t2, &t3 ) < 2) || !t3 || (t - t3 != TUIDL + 3)) :
+ (t3 = 0, (sscanf( buf + 2, "%d %d %n",
&t1, &t2, &t3 ) < 2) || !t3 || (t - t3 != TUIDL + 2)) :
c == '(' || c == ')' || c == '{' || c ==
'}' || c == '[' || c == ']' || c == '!' ?
(sscanf( buf + 2, "%d", &t1 ) != 1) :
c == '+' || c == '&' || c == '-' || c
== '|' || c == '/' || c == '\\' ?
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel