Increment TARGET_WINDOWS_WRITTEN after stream_to_target_write.
Prior to this, TARGET_WINDOWS_WRITTEN would be incremented before
the call to stream_to_target_write if the target was nonzero size
and write_target succeeded. This caused tgt->start to be set
incorrectly. This confused mapio but not xdelta, leading to
correct target windows written to incorrect locations.
Change-Id: I76db5281a749a20d0e63b8126238eb1886d87a1c
diff --git a/syspatch.c b/syspatch.c
index a90e031..3b7b24c 100644
--- a/syspatch.c
+++ b/syspatch.c
@@ -196,10 +196,12 @@
if (tgt->length) {
if (write_target(tgt, target_state) != 0)
return -1;
- TARGET_WINDOWS_WRITTEN += 1;
}
if (stream_to_target_write(stream, tgt) != 0)
return -1;
+ if (tgt->length) {
+ TARGET_WINDOWS_WRITTEN += 1;
+ }
return 0;
}