From: Vadim Zeitlin Date: Sun, 8 Sep 2002 00:49:26 +0000 (+0000) Subject: fixed (yet another?) crash in wxStrtok X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/72d35070d8d725aa3a40002a14144b8e3eb65793 fixed (yet another?) crash in wxStrtok git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@17071 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index 63ae0e26e7..db698b6e57 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -920,22 +920,35 @@ int WXDLLEXPORT wxStrnicmp(const wxChar *s1, const wxChar *s2, size_t n) #ifndef wxStrtok WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr) { - if (!psz) psz = *save_ptr; - psz += wxStrspn(psz, delim); - if (!*psz) { - *save_ptr = (wxChar *)NULL; - return (wxChar *)NULL; - } - wxChar *ret = psz; - psz = wxStrpbrk(psz, delim); - if (!psz) *save_ptr = (wxChar*)NULL; - else { - *psz = wxT('\0'); - *save_ptr = psz + 1; - } - return ret; + if (!psz) + { + psz = *save_ptr; + if ( !psz ) + return NULL; + } + + psz += wxStrspn(psz, delim); + if (!*psz) + { + *save_ptr = (wxChar *)NULL; + return (wxChar *)NULL; + } + + wxChar *ret = psz; + psz = wxStrpbrk(psz, delim); + if (!psz) + { + *save_ptr = (wxChar*)NULL; + } + else + { + *psz = wxT('\0'); + *save_ptr = psz + 1; + } + + return ret; } -#endif +#endif // wxStrtok #ifndef wxSetlocale WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale)