[tex-k] dvips: inconsistent search of PK and TFM files (Karl Berry)

Doug McKenna doug at mathemaesthetics.com
Fri Mar 11 16:03:49 CET 2022

Karl -

In the line within the |(!noomega)| block:

      if ((tfmfile = search(d, full_name, READBIN)) != NULL) {

is it appropriate to be assigning the result of |search()| for a ".otf"
font to a global variable labeled |tfmfile|?  Maybe it is, but prima
facie, it seems like a bug or bug-to-be.

Also, the subroutine has a memory leak in the very
unlikely event that "cmr10.tfm" is not found.
The last lines of of the subroutine should be

   error("! I can't find cmr10.tfm; please reinstall me with proper paths");
   free(full_name);     <-- Add this to fix memory leak

The following rewrite is clearer and shorter by virtue
of not duplicating all the cleanup-up-on-return code,
and getting rid of the fairly pointless local variable |d|,
which as near as I can tell provides no benefit in either
speed or clarity for a successful file search.

tfmopen(register fontdesctype *fd)
   char *full_name;
   char *stem_name = concat(fd->area, fd->name);
   if (!noomega) {            /* search for .ofm first */
      full_name = concat(stem_name, ".ofm");
      if ((tfmfile = search(ofmpath, full_name, READBIN)) != NULL)
         goto done;

   /* try tfm */
   full_name = concat(stem_name, ".tfm");
   if ((tfmfile = search(tfmpath, full_name, READBIN)) == NULL) {
      sprintf(errbuf, "Can't open font metric file %.999s", full_name);
      error("I will use cmr10.tfm instead, so expect bad output.");
      if ((tfmfile=search(tfmpath, "cmr10.tfm", READBIN)) == NULL)
         error("! I can't find cmr10.tfm; please reinstall me with proper paths");


IMHO, the alleged evils of a single labeled |goto| in a short routine
like this are outweighed by the evident evils of multiple conditional
|return| statements, each with duplicated cleanup code.

FWIW, just based on looking at the posted code.

- Doug McKenna

More information about the tex-k mailing list.