printk: Fix log_buf_copy termination.

If idx was non-zero and the log had wrapped, len did not get truncated
to stop at the last byte written to the log.
diff --git a/kernel/printk.c b/kernel/printk.c
index 4f3a648..2a8a61c 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -319,8 +319,8 @@
 	if (idx < 0 || idx >= max) {
 		ret = -1;
 	} else {
-		if (len > max)
-			len = max;
+		if (len > max - idx)
+			len = max - idx;
 		ret = len;
 		idx += (log_end - max);
 		while (len-- > 0)