summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2010-07-30 13:24:50 -0700
committerKenneth Graunke <[email protected]>2010-07-30 13:26:14 -0700
commit805cbf39224580fdb85b09a21be7cbc658f0ecf6 (patch)
treef25a3491ee5e9e1a055ecedca3a53b9e4823698b /src/glsl
parent0cf545ec696ab450c3f5ee65d7a0c2a5d9dca409 (diff)
glcpp: Don't look for backslashes before the beginning of the string.
Fixes a valgrind error.
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/glcpp/pp.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/glsl/glcpp/pp.c b/src/glsl/glcpp/pp.c
index 1ce829a2c97..7aa1a968de7 100644
--- a/src/glsl/glcpp/pp.c
+++ b/src/glsl/glcpp/pp.c
@@ -93,12 +93,16 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
const char *newline;
while ((newline = strchr(search_start, '\n')) != NULL) {
const char *backslash = NULL;
+
+ /* # of characters preceding the newline. */
+ int n = newline - shader;
+
/* Find the preceding '\', if it exists */
- if (newline[-1] == '\\') {
+ if (n >= 1 && newline[-1] == '\\')
backslash = newline - 1;
- } else if (newline[-1] == '\r' && newline[-2] == '\\') {
+ else if (n >= 2 && newline[-1] == '\r' && newline[-2] == '\\')
backslash = newline - 2;
- }
+
/* Double backslashes don't count (the backslash is escaped) */
if (backslash != NULL && backslash[-1] == '\\') {
backslash = NULL;