Tighten type info for d_strdup
The allocated block is part of the dmem subsystem, so return a type that reflects that.
This commit is contained in:
parent
81dd23b151
commit
1c2e1c6946
|
@ -11,6 +11,7 @@
|
|||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include "dxxsconf.h"
|
||||
#include "u_mem.h"
|
||||
#include "dsx-ns.h"
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
@ -39,11 +40,10 @@ int d_strnicmp(const char *s1, const char *s2, uint_fast32_t n);
|
|||
#endif
|
||||
extern void d_strlwr( char *s1 );
|
||||
#ifdef DEBUG_MEMORY_ALLOCATIONS
|
||||
char *d_strdup(const char *str, const char *, const char *, unsigned) __attribute_malloc();
|
||||
RAIIdmem<char[]> d_strdup(const char *str, const char *, const char *, unsigned);
|
||||
#define d_strdup(str) (d_strdup(str, #str, __FILE__,__LINE__))
|
||||
#else
|
||||
#include <cstring>
|
||||
#define d_strdup strdup
|
||||
RAIIdmem<char[]> d_strdup(const char *str);
|
||||
#endif
|
||||
|
||||
#if DXX_USE_EDITOR
|
||||
|
|
|
@ -95,8 +95,8 @@ namespace {
|
|||
struct cmd_queue_t
|
||||
{
|
||||
RAIIdmem<char[]> command_line;
|
||||
explicit cmd_queue_t(char *p) :
|
||||
command_line(p)
|
||||
explicit cmd_queue_t(RAIIdmem<char[]> p) :
|
||||
command_line(std::move(p))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -348,7 +348,7 @@ static void cmd_alias(unsigned long argc, const char *const *const argv)
|
|||
alias->name[sizeof(alias->name) - 1] = 0;
|
||||
strncpy(alias->name, argv[1], sizeof(alias->name) - 1);
|
||||
}
|
||||
alias->value.reset(d_strdup(buf));
|
||||
alias->value = d_strdup(buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -109,15 +109,23 @@ void d_strupr(std::array<char, PATH_MAX> &out, const std::array<char, PATH_MAX>
|
|||
#endif
|
||||
|
||||
#ifdef DEBUG_MEMORY_ALLOCATIONS
|
||||
char *(d_strdup)(const char *str, const char *var, const char *file, unsigned line)
|
||||
RAIIdmem<char[]> (d_strdup)(const char *str, const char *var, const char *file, unsigned line)
|
||||
#else
|
||||
RAIIdmem<char[]> (d_strdup)(const char *str)
|
||||
#endif
|
||||
{
|
||||
char *newstr;
|
||||
RAIIdmem<char[]> newstr;
|
||||
#ifndef DEBUG_MEMORY_ALLOCATIONS
|
||||
const auto var = nullptr;
|
||||
const auto file = nullptr;
|
||||
const unsigned line = 0;
|
||||
#endif
|
||||
|
||||
const auto len = strlen(str) + 1;
|
||||
MALLOC<char>(newstr, len, var, file, line);
|
||||
return static_cast<char *>(memcpy(newstr, str, len));
|
||||
MALLOC<char[]>(newstr, len, var, file, line);
|
||||
memcpy(newstr.get(), str, len);
|
||||
return newstr;
|
||||
}
|
||||
#endif
|
||||
|
||||
// remove extension from filename
|
||||
void removeext(const char *const filename, std::array<char, 20> &out)
|
||||
|
|
|
@ -72,7 +72,7 @@ static PHYSFSX_counted_list file_getdirlist(const char *dir)
|
|||
list.release();
|
||||
list.reset(r);
|
||||
std::move_backward(r, r + NumDirs, r + NumDirs + 1);
|
||||
list[0] = d_strdup("..");
|
||||
list[0] = strdup("..");
|
||||
}
|
||||
list.set_count(NumDirs);
|
||||
return list;
|
||||
|
|
|
@ -840,10 +840,8 @@ int menubar_init(grs_canvas &canvas, const char *const file)
|
|||
CommaParse( 2, buf1, buffer );
|
||||
ul_xlate(buf1);
|
||||
|
||||
item.Text.reset(d_strdup(buf1[0] == '-' ? buf1 : (snprintf(buf2, sizeof(buf2), " %.197s ", buf1), buf2)));
|
||||
|
||||
item.InactiveText.reset(d_strdup(item.Text.get()));
|
||||
|
||||
item.Text = d_strdup(buf1[0] == '-' ? buf1 : (snprintf(buf2, sizeof(buf2), " %.197s ", buf1), buf2));
|
||||
item.InactiveText = d_strdup(item.Text.get());
|
||||
for (int i = 0, j = 0;; i++ )
|
||||
{
|
||||
np = item.Text[i];
|
||||
|
|
|
@ -71,7 +71,7 @@ void ui_draw_radio(UI_DIALOG &dlg, UI_GADGET_RADIO &radio)
|
|||
std::unique_ptr<UI_GADGET_RADIO> ui_add_gadget_radio(UI_DIALOG &dlg, short x, short y, short w, short h, short group, const char *const text)
|
||||
{
|
||||
auto radio = ui_gadget_add<UI_GADGET_RADIO>(dlg, x, y, x + w - 1, y + h - 1);
|
||||
radio->text = RAIIdmem<char[]>(d_strdup(text));
|
||||
radio->text = d_strdup(text);
|
||||
radio->width = w;
|
||||
radio->height = h;
|
||||
radio->position = 0;
|
||||
|
|
|
@ -300,7 +300,7 @@ static void nm_string(grs_canvas &canvas, const grs_font &cv_font, const int w1,
|
|||
RAIIdmem<char[]> s2;
|
||||
if (w1 > 0 && (p = strchr(s, '\t')))
|
||||
{
|
||||
s2.reset(d_strdup(s));
|
||||
s2 = d_strdup(s);
|
||||
s1 = s2.get();
|
||||
*std::next(s2.get(), std::distance(s, p)) = '\0';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue