BUG/MINOR: ist: only store NUL byte on succeeded alloc

The trailing NUL added at the end of istdup() by recent commit de0216758
("BUG/MINOR: ist: allocate nul byte on istdup") was placed outside of
the pointer validity test, rightfully showing null deref warnings. This
fix should be backported along with the fix above, to the same versions.

(cherry picked from commit a4d44250ebda83aac986d94e49004c470a19681e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9ba0ff5b40cd6155b602098fe64f0bed7aaf8a6d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9d90e250db096defc79a392509a4c2930eb201b7)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 2b678443fd7460c2d0651bb624c049be1ea64a70)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit e753dbe607d70c372309154b879d64e33d347255)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/include/import/ist.h b/include/import/ist.h
index a63d95e..f8cd1fa 100644
--- a/include/import/ist.h
+++ b/include/import/ist.h
@@ -943,8 +943,8 @@
 
 	if (isttest(dst)) {
 		istcpy(&dst, src, src.len);
+		dst.ptr[dst.len] = '\0';
 	}
-	dst.ptr[dst.len] = '\0';
 
 	return dst;
 }