/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
- * AutoOpts is Copyright (C) 1992-2013 by Bruce Korb - all rights reserved
+ * AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved
*
* AutoOpts is available under any one of two licenses. The license
* in use must be one of these two and the choice is under the control
* private:
*
* what: translate and construct a path
- * arg: + char* + p_buf + The result buffer +
- * arg: + int + b_sz + The size of this buffer +
- * arg: + char const* + fname + The input name +
- * arg: + char const* + prg_path + The full path of the current program +
+ * arg: + char * + p_buf + The result buffer +
+ * arg: + int + b_sz + The size of this buffer +
+ * arg: + char const * + fname + The input name +
+ * arg: + char const * + prg_path + The full path of the current program +
*
* ret-type: bool
* ret-desc: true if the name was handled, otherwise false.
char const * path;
char const * pz;
int skip = 2;
+ size_t fname_len;
+ size_t dir_len; //!< length of the directory portion of the path to the exe
switch (fname[2]) {
case DIRCH:
if (strchr(prg_path, DIRCH) != NULL)
path = prg_path;
else {
- path = pathfind(getenv("PATH"), (char*)prg_path, "rx");
+ path = pathfind(getenv("PATH"), (char *)prg_path, "rx");
if (path == NULL)
return false;
if (pz == NULL)
return false;
- fname += skip;
+ fname += skip;
+ fname_len = strlen(fname) + 1; // + NUL byte
+ dir_len = (pz - path) + 1; // + dir sep character
/*
* Concatenate the file name to the end of the executable path.
* The result may be either a file or a directory.
*/
- if ((unsigned)(pz - path) + 1 + strlen(fname) >= (unsigned)b_sz)
+ if (dir_len + fname_len > (unsigned)b_sz)
return false;
- memcpy(buf, path, (size_t)((pz - path)+1));
- strcpy(buf + (pz - path) + 1, fname);
+ memcpy(buf, path, dir_len);
+ memcpy(buf + dir_len, fname, fname_len);
/*
* If the "path" path was gotten from "pathfind()", then it was
if (dir_part == NULL)
return false;
- if (strlen(dir_part) + 1 + strlen(name) >= (unsigned)buf_sz)
- return false;
+ {
+ size_t dir_len = strlen(dir_part);
+ size_t nm_len = strlen(name) + 1;
+
+ if (dir_len + nm_len >= (unsigned)buf_sz)
+ return false;
+ memcpy(buf, dir_part, dir_len);
+ memcpy(buf + dir_len, name, nm_len);
+ }
- sprintf(buf, "%s%s", dir_part, name);
return true;
}
LOCAL void
munge_str(char * txt, tOptionLoadMode mode)
{
- char * pzE;
+ char * end;
if (mode == OPTION_LOAD_KEEP)
return;
char * src = SPN_WHITESPACE_CHARS(txt+1);
size_t l = strlen(src) + 1;
memmove(txt, src, l);
- pzE = txt + l - 1;
+ end = txt + l - 1;
} else
- pzE = txt + strlen(txt);
+ end = txt + strlen(txt);
- pzE = SPN_WHITESPACE_BACK(txt, pzE);
- *pzE = NUL;
+ end = SPN_WHITESPACE_BACK(txt, end);
+ *end = NUL;
if (mode == OPTION_LOAD_UNCOOKED)
return;
case '\'': break;
}
- switch (pzE[-1]) {
+ switch (end[-1]) {
default: return;
case '"':
case '\'': break;
*
* what: process a string for an option name and value
*
- * arg: tOptions*, opts, program options descriptor
- * arg: char const*, line, NUL-terminated text
+ * arg: tOptions *, opts, program options descriptor
+ * arg: char const *, line, NUL-terminated text
*
* doc:
*