[Plib-cvs] plib/src/pui puFileSelector.cxx,1.27,1.28
Brought to you by:
sjbaker
From: Sebastian U. <ud...@us...> - 2002-09-20 00:26:11
|
Update of /cvsroot/plib/plib/src/pui In directory usw-pr-cvs1:/tmp/cvs-serv19613 Modified Files: puFileSelector.cxx Log Message: John F. Fay / me: Fixed puFileSelector bug with long path names Index: puFileSelector.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puFileSelector.cxx,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- puFileSelector.cxx 2 Sep 2002 06:05:45 -0000 1.27 +++ puFileSelector.cxx 20 Sep 2002 00:26:07 -0000 1.28 @@ -204,31 +204,35 @@ { /* If this is a directory - then descend into it and refresh */ - if ( strlen ( dst ) + strlen ( src ) + 2 >= PUSTRING_MAX ) - { - ulSetError ( UL_WARNING, - "PUI: puFileSelector - path is too long, max is %d.", PUSTRING_MAX ) ; - return ; - } + src++ ; /* Remove leading '[' */ + + int dst_len = strlen ( dst ) ; + int src_len = strlen ( src ) ; + char *new_dst = new char [ dst_len + src_len + 1 ] ; + + memcpy ( new_dst, dst, dst_len ) ; + memcpy ( new_dst + dst_len, src, src_len + 1 ) ; /* Copy trailing '\0' */ + + /* Replace trailing ']' with slash */ + new_dst [ dst_len + src_len - 1 ] = SLASH[0] ; - strcat ( dst, &src[1] ) ; /* Remove leading '[' */ - dst [ strlen ( dst ) - 1 ] = SLASH[0] ; /* Replace trailing ']' with slash */ file_selector -> find_files () ; - file_selector -> __getInput() -> setValue ( dst ) ; + file_selector -> __getInput() -> setValue ( new_dst ) ; + delete [] new_dst ; return ; } /* If this is a regular file - then just append it to the string */ - if ( strlen ( dst ) + strlen ( src ) + 2 >= PUSTRING_MAX ) - { - ulSetError ( UL_WARNING, - "PUI: puFileSelector - path is too long, max is %d.", PUSTRING_MAX ) ; - return ; - } + int dst_len = strlen ( dst ) ; + int src_len = strlen ( src ) ; + char *new_dst = new char [ dst_len + src_len + 1 ] ; - strcat ( dst, src ) ; - file_selector -> __getInput() -> setValue ( dst ) ; + memcpy ( new_dst, dst, dst_len ) ; + memcpy ( new_dst + dst_len, src, src_len + 1 ) ; /* Copy trailing '\0' */ + + file_selector -> __getInput() -> setValue ( new_dst ) ; + delete [] new_dst ; } else { |