From 5e1ec287982933fdaaf2eb8e5ddd1f73e1793654 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 12 May 2013 18:51:19 +0000 Subject: [PATCH] build.c: fix strcpy() with overlapping arguments. git-svn-id: https://svn.eduke32.com/eduke32@3750 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/build.c | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index ab47742ea..712bede93 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -220,6 +220,12 @@ static void correct_ornamented_sprite(int32_t i, int32_t hitw); static int32_t getfilenames(const char *path, const char *kind); +// Get basename of BUILD file name (forward slashes as directory separators). +static const char *getbasefn(const char *fn) +{ + const char *slash = Bstrrchr(fn, '/'); + return slash ? slash+1 : fn; +} void clearkeys(void) { @@ -7682,9 +7688,16 @@ CANCEL: bad = 0; + // Back up full name. Bstrcpy(selectedboardfilename, boardfilename); - if (Bstrrchr(boardfilename, '/')) - Bstrcpy(boardfilename, Bstrrchr(boardfilename, '/')+1); + + // Get base name. + { + const char *basefn = getbasefn(boardfilename); + + if (basefn != boardfilename) + Bmemmove(boardfilename, basefn, Bstrlen(basefn)+1); + } i = 0; while (boardfilename[i] != 0 && i < 64) @@ -7739,6 +7752,7 @@ CANCEL: Bstrcpy(&boardfilename[i], ".map"); + // Update full name with new basename. slash = Bstrrchr(selectedboardfilename,'/'); Bstrcpy(slash ? slash+1 : selectedboardfilename, boardfilename); @@ -7970,25 +7984,15 @@ static void SaveBoardAndPrintMessage(const char *fn) // get the file name of the file that would be written if SaveBoard(fn, 0) was called const char *GetSaveBoardFilename(const char *fn) { - const char *f; - if (!fn) fn = boardfilename; if (pathsearchmode) - f = fn; - else - { - // virtual filesystem mode can't save to directories so drop the file into - // the current directory - f = Bstrrchr(fn, '/'); - if (!f) - f = fn; - else - f++; - } + return fn; - return f; + // virtual filesystem mode can't save to directories so drop the file into + // the current directory + return getbasefn(fn); } // flags: 1:no ExtSaveMap (backup.map) and no taglabels saving @@ -9201,12 +9205,7 @@ static char g_oldpath[BMAX_PATH]; static void menuselect_try_findlast(void) { // PK 20080103: start with last selected map - const char *boardbasename = Bstrrchr(boardfilename, '/'); - - if (!boardbasename) - boardbasename=boardfilename; - else - boardbasename++; + const char *boardbasename = getbasefn(boardfilename); for (; findfileshigh; findfileshigh=findfileshigh->next) if (!Bstrcmp(findfileshigh->name, boardbasename))