Hi Willem,

On Freitag, 18. Mai 2018 10:30:28 CEST you wrote:

> On March 14th you introduced a PR entitled Cleanup: fix "unsave"
> snprintf()s in plannernotes.c
> <https://github.com/Subsurface-divelog/subsurface/commit/a4834e198d55d50a44d
> 6f80e2137777b64652ce7#diff-0df10959bbcbe5342528360ce6f541a5> for Subsurface.
> 
> This PR affected the function  add_icd_entry() in plannernotes.c. The
> changes, unfortunately, introduced a bug in the display of the icd data
> for a dive. I include a sample dive plan so that you can see the effect
> of this change in code. Activate the display of icd data in Preferences,
> open the attached dive plan and edit the dive plan within the planner.
> You will see random information being added to the icd data. In fact the
> icd data are quite messed up because the table should include two lines
> of gas change information. At least part of the problem lies in lines
> 55-68 of plannernotes.c.

Unfortunately, I can't reproduce this (don't get an ICD-warning?). But there 
is an obvious bug in the handling of the ICD buffer. Could you try the 
attached patch?

Thank you,

Berthold
>From d7158dfdfeca7ea8e73cadb1cb2a77b057e84278 Mon Sep 17 00:00:00 2001
From: Berthold Stoeger <[email protected]>
Date: Fri, 18 May 2018 11:44:11 +0200
Subject: [PATCH] Plannernotes: '\0'-terminate ICD-buffer

When creating the ICD-notes the membuffer was not '\0'-terminated,
leading to output of stale data.

Reported-by: Willem Ferguson <[email protected]>
Signed-off-by: Berthold Stoeger <[email protected]>
---
 core/plannernotes.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/core/plannernotes.c b/core/plannernotes.c
index efd71b16c..cf5b682a3 100644
--- a/core/plannernotes.c
+++ b/core/plannernotes.c
@@ -524,6 +524,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
 	/* For trimix OC dives, if an icd table header and icd data were printed to buffer, then add the ICD table here */
 	if (!icdtableheader && prefs.show_icd) {
 		put_string(&icdbuf, "</tbody></table>"); // End the ICD table
+		mb_cstring(&icdbuf);
 		put_string(&buf, icdbuf.buffer); // ..and add it to the html buffer
 		if (icdwarning) { // If necessary, add warning
 			put_format(&buf, "<span style='color: red;'>%s</span> %s",
-- 
2.14.1

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to