diff --git a/src/engine/Account.c b/src/engine/Account.c index e39cafdfbd..17ff5b9fe1 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -421,11 +421,12 @@ xaccCheckDateOrder (Account * acc, Split *split ) { int outOfOrder = 0; Split *s; - Split *prevSplit; - Split *nextSplit; + Split *prevSplit = NULL; + Split *nextSplit = NULL; int position; if (NULL == acc) return 0; + if (NULL == split) return 0; /* find the split's location in the array */ position = 0; @@ -438,12 +439,15 @@ xaccCheckDateOrder (Account * acc, Split *split ) if (!s) { printf ("Internal Error: xaccCheckDateOrder(): "); - printf (" split not present in account \n"); + printf (" split %s not present in account \n", split); return 0; } - prevSplit = acc->splits [position-1]; - nextSplit = acc->splits [position+1]; + /* if zeroth split, then there is no previous */ + if (0 < position) prevSplit = acc->splits [position-1]; + + /* if last split, OK, since array is null terminated, and last+1 is null */ + nextSplit = acc->splits [position+1]; /* figure out if the transactions are out of order */ if (NULL != prevSplit) {