Revision: 77061
          http://sourceforge.net/p/brlcad/code/77061
Author:   starseeker
Date:     2020-09-04 15:30:34 +0000 (Fri, 04 Sep 2020)
Log Message:
-----------
More uniformly define MAXPATHLEN across the code.

Tcl defines MAXPATHLEN, and there was a potential for different
definitions between their headers and ours.  Not certain, but that is
one possible source of the strange realpath crash observed on Linux
but not reproducible in isolation - if code with one definition of
MAXPATHLEN created a buffer and then fed it to a library compiled using
a different definition, those different assumptions are a source of
possible trouble.  I think that's what was happening with the whoami.c
code after I switched it to using MAXPATHLEN.  Previously that code
called realpath directly rather than bu_file_realpath.  After the
MAXPATHLEN switch, those raw realpath calls triggered a segfault on
Linux - most likely due to a non-PATH_MAX definition of MAXPATHLEN
previously being defaulted to by the bu/defines.h definition.

Move the MAXPATHLEN definition to common.h, which is always included
before tcl.h in our code, and add a couple definitions from the Tcl
headers to use as fallbacks.  Would be nice if there is some way to
systematically check for this kind of issue...

Modified Paths:
--------------
    brlcad/trunk/include/bu/defines.h
    brlcad/trunk/include/common.h

Modified: brlcad/trunk/include/bu/defines.h
===================================================================
--- brlcad/trunk/include/bu/defines.h   2020-09-04 14:08:38 UTC (rev 77060)
+++ brlcad/trunk/include/bu/defines.h   2020-09-04 15:30:34 UTC (rev 77061)
@@ -69,22 +69,6 @@
 #endif  /* DIR_SEPARATOR */
 
 /**
- * Maximum length of a filesystem path.  Typically defined in a system
- * file but if it isn't set, we create it.
- */
-#ifndef MAXPATHLEN
-#  ifdef PATH_MAX
-#    define MAXPATHLEN PATH_MAX
-#  else
-#    ifdef _MAX_PATH
-#      define MAXPATHLEN _MAX_PATH
-#    else
-#      define MAXPATHLEN 1024
-#    endif
-#  endif
-#endif
-
-/**
  * set to the path list separator character
  */
 #if defined(PATH_SEPARATOR)

Modified: brlcad/trunk/include/common.h
===================================================================
--- brlcad/trunk/include/common.h       2020-09-04 14:08:38 UTC (rev 77060)
+++ brlcad/trunk/include/common.h       2020-09-04 15:30:34 UTC (rev 77061)
@@ -227,6 +227,23 @@
 #endif
 
 /**
+ * Maximum length of a filesystem path.  Typically defined in a system
+ * file but if it isn't set, we create it.
+ */
+#ifndef MAXPATHLEN
+#  include <limits.h> // Consistently define (or not) PATH_MAX
+#  ifdef PATH_MAX
+#    define MAXPATHLEN PATH_MAX
+#  elif defined(MAX_PATH)
+#    define MAXPATHLEN MAX_PATH
+#  elif defined(_MAX_PATH)
+#    define MAXPATHLEN _MAX_PATH
+#  else
+#    define MAXPATHLEN 2048
+#  endif
+#endif
+
+/**
  * Provide a means to conveniently test the version of the GNU
  * compiler.  Use it like this:
  *

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to