[Libreoffice] Why define a string just to use a copy of the string a few lines later?

Christian Lohmaier lohmaier+libreoffice at googlemail.com
Thu May 5 19:25:53 PDT 2011


Hi *,

Looking at this change (as it breaks with WaE because that function is
unused on Mac)

http://cgit.freedesktop.org/libreoffice/libs-core/diff/desktop/unx/source/start.c?id=1a790d00100183abfa71666d437af9115940c32a

I realize that it's either too late/I'm too tired or I'm lacking some
basic understanding....

Fix for the WaE breaker is easy (just conditionalize it for non-mac as
in the exec_pagein method), but the code did let me stumble, so I take
the opportunity to learn and ask....

+#define REL_PATH "/../basis-link/program"
+static char *build_pagein_path (Args *args, const char *pagein_name)
+{
+    char *path;
+    rtl_String *app_path;
+
+    app_path = ustr_to_str (args->pAppPath);
+    path = malloc (app_path->length + strlen (pagein_name) + sizeof
(REL_PATH) + 8);
+    strcpy (path, "@");
+    strcpy (path + 1, rtl_string_getStr (app_path));
+    strcat (path, "/../basis-link/program/");
+    strcat (path, pagein_name);
+
+    rtl_string_release( app_path );
+
+    return path;
+}

So it defines REL_PATH - so far no problem - but it only uses it for
the siezeof, but then on the strcat it is used as copy of the string,
and what is really causing my confusion is that it has a trailing
slash - so sizeof counts one character less (OK, no problem, account
for the nullbyte for terminating the string - but if that's the idea,
it's not really obvious, so I guess that's not the case but rather an
oversight)

And the second part is - why the "+8"?

It needs to hold
@ + app_path (why strcpy instead of strcat here - doesn't make a
difference, or does it?) + /../basis-link/program/ + pagein_name +
nullbyte

What am I missing?
/me feels dumb, and fears the answer :-))

ciao
Christian


More information about the LibreOffice mailing list