Permalink
Browse files

COMMON: Move new_strdup to common/str.cpp

  • Loading branch information...
ccawley2011 authored and sev- committed Aug 18, 2018
1 parent d43732a commit 7a437e909ce81894d4ad9f1e22b55e609becb9bb
Showing with 13 additions and 11 deletions.
  1. +10 −0 common/str.cpp
  2. +1 −0 common/str.h
  3. +2 −11 graphics/fonts/bdf.cpp
@@ -1058,3 +1058,13 @@ int scumm_strnicmp(const char *s1, const char *s2, uint n) {
} while (l1 == l2 && l1 != 0);
return l1 - l2;
}

// Portable implementation of strdup.
char *scumm_strdup(const char *in) {
const size_t len = strlen(in) + 1;
char *out = new char[len];
if (out) {
strcpy(out, in);
}
return out;
}
@@ -482,5 +482,6 @@ size_t strnlen(const char *src, size_t maxSize);

extern int scumm_stricmp(const char *s1, const char *s2);
extern int scumm_strnicmp(const char *s1, const char *s2, uint n);
extern char *scumm_strdup(const char *in);

#endif
@@ -700,15 +700,6 @@ BdfFont *BdfFont::loadFromCache(Common::SeekableReadStream &stream) {
return new BdfFont(data, DisposeAfterUse::YES);
}

static char *new_strdup(const char *in) {
const size_t len = strlen(in) + 1;
char *out = new char[len];
if (out) {
strcpy(out, in);
}
return out;
}

BdfFont *BdfFont::scaleFont(BdfFont *src, int newSize) {
if (!src) {
warning("Empty font reference in scale font");
@@ -734,8 +725,8 @@ BdfFont *BdfFont::scaleFont(BdfFont *src, int newSize) {
data.firstCharacter = src->_data.firstCharacter;
data.defaultCharacter = src->_data.defaultCharacter;
data.numCharacters = src->_data.numCharacters;
data.familyName = new_strdup(src->_data.familyName);
data.slant = new_strdup(src->_data.slant);
data.familyName = scumm_strdup(src->_data.familyName);
data.slant = scumm_strdup(src->_data.slant);

BdfBoundingBox *boxes = new BdfBoundingBox[data.numCharacters];
for (int i = 0; i < data.numCharacters; ++i) {

0 comments on commit 7a437e9

Please sign in to comment.