Subject: Re: bug#30785: Man pages truncated, repeated

From: Pierre Neidhardt <[email-masked]>
Date: Mon, 14 Jan 2019 17:57:12 +0100

> (libs/libgroff/localcharset.c's locale_charset looks overly complicated, WTF?)

Oh dear... relocatep.cpp is not much better, here is the offending function:

--8<---------------cut here---------------start------------->8---
// Strip the installation prefix and replace it
// with the current installation prefix; return the relocated path.
char *relocatep(const char *path)
{
#if DEBUG
  fprintf(stderr, "relocatep: path = %s\n", path);
  fprintf(stderr, "relocatep: INSTALLPATH = %s\n", INSTALLPATH);
  fprintf(stderr, "relocatep: INSTALLPATHLEN = %d\n", INSTALLPATHLEN);
#endif
  if (!curr_prefix)
    set_current_prefix();
  if (strncmp(INSTALLPATH, path, INSTALLPATHLEN))
    return strsave(path);
  char *relative_path = (char *)path + INSTALLPATHLEN;
  size_t relative_path_len = strlen(relative_path);
  char *relocated_path = new char[curr_prefix_len + relative_path_len + 1];
  strcpy(relocated_path, curr_prefix);
  strcat(relocated_path, relative_path);
#if DEBUG
  fprintf(stderr, "relocated_path: %s\n", relocated_path);
#endif /* DEBUG */
  return relocated_path;
}
--8<---------------cut here---------------end--------------->8---

I don't even get the use case of the function...  From locale_charset, it seems
that the argument is LIBDIR.

So maybe INSTALLPATH and/or LIBDIR is not properly set when we compile groff.

> Maybe argv[0] is still the cause, but try setting the environment variable
> LC_ALL to "C" to disable locales before invoking "man".  Does this make it not
> crash?

This works indeed!  Can you see a fix then?

-- 
Pierre Neidhardt
https://ambrevar.xyz/