summaryrefslogtreecommitdiffhomepage
path: root/src/text.c
diff options
context:
space:
mode:
authorBenjamin Stigsen <[email protected]>2020-04-04 14:25:57 +0200
committerGitHub <[email protected]>2020-04-04 14:25:57 +0200
commit9c280bc7afcca1e3c813fc5620d9a0074e5a9db9 (patch)
treed76350d0358251cd370a45a280b854c86013b903 /src/text.c
parent8444c3f705f36e1c8adaef26ccf4ee4b1c39a2e5 (diff)
downloadraylib-9c280bc7afcca1e3c813fc5620d9a0074e5a9db9.tar.gz
raylib-9c280bc7afcca1e3c813fc5620d9a0074e5a9db9.zip
TextReplace changes (#1172)
- Added NULL return if the replacement string (`by`) is empty - Reordered sanity checks since there's no need to initialize variables if the strings are invalid.
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/text.c b/src/text.c
index fdcf244a..21bb8808 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1179,6 +1179,9 @@ const char *TextSubtext(const char *text, int position, int length)
// WARNING: Internally allocated memory must be freed by the user (if return != NULL)
char *TextReplace(char *text, const char *replace, const char *by)
{
+ // Sanity checks and initialization
+ if (!text || !replace || !by || by[0] == '\0') return NULL;
+
char *result;
char *insertPoint; // Next insert point
@@ -1188,13 +1191,9 @@ char *TextReplace(char *text, const char *replace, const char *by)
int lastReplacePos; // Distance between replace and end of last replace
int count; // Number of replacements
- // Sanity checks and initialization
- if (!text || !replace) return NULL;
-
replaceLen = TextLength(replace);
if (replaceLen == 0) return NULL; // Empty replace causes infinite loop during count
- if (!by) by = ""; // Replace by nothing if not provided
byLen = TextLength(by);
// Count the number of replacements needed