[PATCH] Fix window title when no dives selected

Dirk Hohndel dirk at hohndel.org
Fri May 17 08:41:45 PDT 2013


On Fri, 2013-05-17 at 14:01 +0300, Sergey Starosek wrote:
> Print program name and filename when no dives selected.
> 
> Signed-off-by: Sergey Starosek <sergey.starosek at gmail.com>
> ---
>  info.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
diff --git a/info.c b/info.c
index 0abee1c..55df59f 100644
--- a/info.c
+++ b/info.c
@@ -108,7 +108,7 @@ const char *get_window_title(struct dive *dive)
                if (existing_filename) {
                        char *basename;
                        basename =
g_path_get_basename(existing_filename);
-                       len1 = sizeof("Subsurface: ");
+                       len1 = strlen("Subsurface: ");
                        len2 = g_utf8_strlen(basename, -1);
                        sz = (len1 + len2) * sizeof(gunichar);
                        title = malloc(sz);



I don't think this is correct. sizeof gives me len plus the trailing
'\0' - so the actual space the string constant needs. With your change
we have a buffer that is one character short...

So does this fix an actual bug that you can see before the patch or is
this just code that you saw and thought was wrong - because this would
be wrong in the case of char buffer[] = "Subsurface: "; sizeof(buffer) /
strlen(buffer);

The advantage of doing it the way it's in the code before your patch is
that the calculation is done at compile time (instead of runtime) and
there is less risk of forgetting to allow for the trailing '\0'...

/D



More information about the subsurface mailing list