aboutsummaryrefslogtreecommitdiff
path: root/gcc/input.c
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@gcc.gnu.org>2013-11-06 23:51:36 +0100
committerDodji Seketeli <dodji@gcc.gnu.org>2013-11-06 23:51:36 +0100
commit7f4d640cd9ecf834ce2f6ab469076ddd49021374 (patch)
tree44627b6221b370fdd68008a052a86fa6e7c16f32 /gcc/input.c
parent9954c743b9e985bd30194525464a0a8a64697b68 (diff)
downloadgcc-7f4d640cd9ecf834ce2f6ab469076ddd49021374.zip
gcc-7f4d640cd9ecf834ce2f6ab469076ddd49021374.tar.gz
gcc-7f4d640cd9ecf834ce2f6ab469076ddd49021374.tar.bz2
Revert "preprocessor/58580 - preprocessor goes OOM with warning for zero literals"
This reverts commit fc3eff8854861fcd70d33d26095b17fe456fae31. From-SVN: r204490
Diffstat (limited to 'gcc/input.c')
-rw-r--r--gcc/input.c115
1 files changed, 27 insertions, 88 deletions
diff --git a/gcc/input.c b/gcc/input.c
index cb3a0a0..a141a92 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -87,114 +87,53 @@ expand_location_1 (source_location loc,
return xloc;
}
-/* This function reads a line that might contain bytes whose value is
- zero. It returns the number of bytes read. The 'end-of-line'
- character found at the end of the line is not contained in the
- returned buffer. Note that this function has been adapted from
- getline() and _IO_getdelim() GNU C library functions. It's been
- duplicated here because the getline() function is not necessarily
- present on all platforms.
-
- LINEPTR points to a buffer that is to contain the line read.
-
- N points to the size of the the LINEPTR buffer.
-
- FP points to the file to consider. */
-
-static ssize_t
-get_line (char **lineptr, size_t *n, FILE *fp)
+/* Reads one line from file into a static buffer. */
+static const char *
+read_line (FILE *file)
{
- ssize_t cur_len = 0, len;
- char buf[16384];
-
- if (lineptr == NULL || n == NULL)
- return -1;
+ static char *string;
+ static size_t string_len;
+ size_t pos = 0;
+ char *ptr;
- if (*lineptr == NULL || *n == 0)
+ if (!string_len)
{
- *n = 120;
- *lineptr = XNEWVEC (char, *n);
+ string_len = 200;
+ string = XNEWVEC (char, string_len);
}
- len = fread (buf, 1, sizeof buf, fp);
- if (ferror (fp))
- return -1;
-
- for (;;)
+ while ((ptr = fgets (string + pos, string_len - pos, file)))
{
- size_t needed;
- char *t = (char*) memchr (buf, '\n', len);
- if (t != NULL) len = (t - buf);
- if (__builtin_expect (len >= SSIZE_MAX - cur_len, 0))
- return -1;
- needed = cur_len + len + 1;
- if (needed > *n)
+ size_t len = strlen (string + pos);
+
+ if (string[pos + len - 1] == '\n')
{
- char *new_lineptr;
- if (needed < 2 * *n)
- needed = 2 * *n;
- new_lineptr = XRESIZEVEC (char, *lineptr, needed);
- *lineptr = new_lineptr;
- *n = needed;
+ string[pos + len - 1] = 0;
+ return string;
}
- memcpy (*lineptr + cur_len, buf, len);
- cur_len += len;
- if (t != NULL)
- break;
- len = fread (buf, 1, sizeof buf, fp);
- if (ferror (fp))
- return -1;
- if (len == 0)
- break;
+ pos += len;
+ string = XRESIZEVEC (char, string, string_len * 2);
+ string_len *= 2;
}
-
- if (cur_len)
- (*lineptr)[cur_len] = '\0';
- return cur_len;
-}
-
-/* Reads one line from FILE into a static buffer. If LINE_LENGTH is
- *non-null LINE_LENGTH, will be set by this function to the length of
- *the returned line. Note that the returned line can contain several
- *zero bytes. Also note that the returned string is allocated in
- *static storage that is going to be re-used by subsequent invocations
- *of read_line. */
-static const char *
-read_line (FILE *file, int *line_length)
-{
- static char *string;
- static size_t string_len;
- int len;
-
- len = get_line (&string, &string_len, file);
- if (line_length)
- *line_length = len;
- return len ? string : NULL;
+
+ return pos ? string : NULL;
}
/* Return the physical source line that corresponds to xloc in a
buffer that is statically allocated. The newline is replaced by
- the null character. Note that the line can contain several null
- characters, so LINE_LEN, if non-null, points to the actual length
- of the line. */
+ the null character. */
const char *
-location_get_source_line (expanded_location xloc,
- int *line_len)
+location_get_source_line (expanded_location xloc)
{
- const char *buffer = NULL, *ptr;
- int lines = 0, len = 0;
+ const char *buffer;
+ int lines = 1;
FILE *stream = xloc.file ? fopen (xloc.file, "r") : NULL;
if (!stream)
return NULL;
- while ((ptr = read_line (stream, &len)) && lines < xloc.line)
- {
- buffer = ptr;
- lines++;
- if (line_len)
- *line_len = len;
- }
+ while ((buffer = read_line (stream)) && lines < xloc.line)
+ lines++;
fclose (stream);
return buffer;