if (!fopen_e_ever_failed_einval)
{
- char *copy;
-
- copy = (char *) alloca (strlen (opentype) + 2);
- strcpy (copy, opentype);
/* This is a glibc extension but we try it unconditionally on
this path. */
- strcat (copy, "e");
- result = fopen (filename, copy);
+ auto opentype_e = std::string (opentype) + 'e';
+ result = fopen (filename, opentype_e.c_str ());
if (result == NULL && errno == EINVAL)
{
const char *s = *arg;
const char *string;
+ /* Buffer to hold the escaped-processed version of the string. */
+ std::string de_escaped;
+
if (gdb_extensions)
{
string = *arg;
{
/* Parse the format-control string and copy it into the string STRING,
processing some kinds of escape sequence. */
-
- char *f = (char *) alloca (strlen (s) + 1);
- string = f;
-
while (*s != '"' && *s != '\0')
{
int c = *s++;
switch (c = *s++)
{
case '\\':
- *f++ = '\\';
+ de_escaped += '\\';
break;
case 'a':
- *f++ = '\a';
+ de_escaped += '\a';
break;
case 'b':
- *f++ = '\b';
+ de_escaped += '\b';
break;
case 'e':
- *f++ = '\e';
+ de_escaped += '\e';
break;
case 'f':
- *f++ = '\f';
+ de_escaped += '\f';
break;
case 'n':
- *f++ = '\n';
+ de_escaped += '\n';
break;
case 'r':
- *f++ = '\r';
+ de_escaped += '\r';
break;
case 't':
- *f++ = '\t';
+ de_escaped += '\t';
break;
case 'v':
- *f++ = '\v';
+ de_escaped += '\v';
break;
case '"':
- *f++ = '"';
+ de_escaped += '"';
break;
default:
/* ??? TODO: handle other escape sequences. */
break;
default:
- *f++ = c;
+ de_escaped += c;
}
}
- /* Terminate our escape-processed copy. */
- *f++ = '\0';
+ string = de_escaped.c_str ();
/* Whether the format string ended with double-quote or zero, we're
done with it; it's up to callers to complain about syntax. */
gdb_realpath_keepfile (const char *filename)
{
const char *base_name = lbasename (filename);
- char *dir_name;
/* Extract the basename of filename, and return immediately
a copy of filename if it does not contain any directory prefix. */
if (base_name == filename)
return filename;
- dir_name = (char *) alloca ((size_t) (base_name - filename + 2));
- /* Allocate enough space to store the dir_name + plus one extra
- character sometimes needed under Windows (see below), and
- then the closing \000 character. */
- strncpy (dir_name, filename, base_name - filename);
- dir_name[base_name - filename] = '\000';
+ std::string dir_name (filename, base_name - filename);
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
/* We need to be careful when filename is of the form 'd:foo', which
is equivalent of d:./foo, which is totally different from d:/foo. */
- if (strlen (dir_name) == 2 && c_isalpha (dir_name[0]) && dir_name[1] == ':')
- {
- dir_name[2] = '.';
- dir_name[3] = '\000';
- }
+ if (dir_name.size () == 2 && c_isalpha (dir_name[0]) && dir_name[1] == ':')
+ dir_name += '.';
#endif
/* Canonicalize the directory prefix, and build the resulting
filename. If the dirname realpath already contains an ending
directory separator, avoid doubling it. */
- gdb::unique_xmalloc_ptr<char> path_storage = gdb_realpath (dir_name);
+ gdb::unique_xmalloc_ptr<char> path_storage = gdb_realpath (dir_name.c_str ());
const char *real_path = path_storage.get ();
return path_join (real_path, base_name);
}