Patch for long pathnames

Brian Marick (marick@rstcorp.com)
Mon, 22 Nov 1999 15:40:30 -0600


--=====================_770249560==_
Content-Type: text/plain; charset="us-ascii"

Danny Faught (faught@rstcorp.com) discovered that long pathnames cause
AbiWord to dump core on Linux and NT. The attachment is a context diff
between the old and fixed versions of
/src/abiword/abi/src/af/xap/xp/xap_Frame.cpp

I hope that I have delivered the patch correctly - it's been six years
since the last time I mailed a patch.

I have tested this patch on NT using the sources as of 1999/11/21.

The fix merely ignores the leftmost characters in long filenames so that
they do not overflow the buffer used to build the title bar. This is not a
particularly good solution, because the buffer is 256 chars on all
platforms (XAP_*Frame::updateTitle). On NT, at least, the title bar display
is truncated on the right, meaning that the good stuff (filename, dirty
bit) is not visible. It might be better to make the buffer smaller. But
that leads down a slippery slope: why not do more intelligent truncation
(.../foo/bar/baz/quux.abi instead of simply truncating at some random
point)? All of a sudden, we're in platform-specific land and malloc/free
land. Maybe later.
--=====================_770249560==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="xap_Frame.cpp.diff.txt"

*** xap_Frame.cpp-19991121 Sun Nov 21 22:22:10 1999
--- xap_Frame.cpp Mon Nov 22 11:26:36 1999
***************
*** 345,353 ****

const char * XAP_Frame::getTitle(int len) const
{
! // TODO: chop down to fit desired size?
! UT_ASSERT((int)strlen(m_szTitle) < len);
! return m_szTitle;
}

const char * XAP_Frame::getTempNameFromTitle(void) const
--- 345,362 ----

const char * XAP_Frame::getTitle(int len) const
{
! // Returns the pathname being edited (with view and dirty bit
! // '*' adornments), if all that fits. If it doesn't fit,
! // returns the tail of the string that does fit. Would be
! // better to chop it at a pathname separator boundary.
! if ((int)strlen(m_szTitle) <= len)
! {
! return m_szTitle;
! }
! else
! {
! return m_szTitle + (strlen(m_szTitle)-len);
! }
}

const char * XAP_Frame::getTempNameFromTitle(void) const
***************
*** 374,381 ****

if (szName && *szName)
{
! UT_ASSERT(strlen(szName) < 245); // TODO need #define for this number
! strcpy(m_szTitle, szName);
}
else
{
--- 383,414 ----

if (szName && *szName)
{
! // Note: The previous version of this code blew up
! // when assertions were turned on and more than 244
! // characters were to be copied. I now copy only
! // the last 244 characters in that case. I do not know
! // where "244" comes from - the buffer being copied into
! // is currently 512 bytes. However, even 244 characters
! // is way too long for a title bar, so no reason to
! // increase the size to fit more snugly into the buffer.
! // Here's that previous assertion:
! // UT_ASSERT(strlen(szName) < 245); // TODO need #define for this number
!
! // Check that the buffer (with generous room for
! // later decorations) is big enough.
! UT_ASSERT(sizeof(m_szTitle) > 245 + 30);
!
! if (strlen(szName) <= 244)
! {
! strcpy(m_szTitle, szName);
! }
! else
! {
! // copy the tail of the pathname, the useful part.
! // would be a bit more useful to break it at a
! // pathname component separator.
! strcpy(m_szTitle, szName + (strlen(szName) - 244));
! }
}
else
{

--=====================_770249560==_
Content-Type: text/plain; charset="us-ascii"

--
Brian Marick, Reliable Software Technologies, http://www.rstcorp.com
Testing essays and FAQs at http://www.rstcorp.com/marick/
Technical Editor of Software Testing and Quality Engineering, 
http://www.stqemagazine.com

"Let every student of nature take this as his rule, that whatever the mind seizes upon with particular satisfaction is to be held in suspicion." -- Francis Bacon, Novum Organum, 1620. --=====================_770249560==_--



This archive was generated by hypermail 1.03b2.