From bd8273fe29cec51f66fcb55e1e83f65b7d0e6ec3 Mon Sep 17 00:00:00 2001 From: dim Date: Wed, 2 Apr 2014 06:17:57 +0000 Subject: [PATCH] MFC r263775: Avoid "cc1: warning: is shorter than expected" when using GNU cpp in combination with dtrace scripts, which have "#!/usr/sbin/dtrace -Cs" shebang lines. This is because dtrace positions the file pointer after the shebang line, before passing the file to GNU cpp. To fix the warning, adjust the size downwards by the current position, after a bit of sanity checking. Suggested by: avg git-svn-id: svn://svn.freebsd.org/base/stable/10@264032 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- contrib/gcclibs/libcpp/files.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/gcclibs/libcpp/files.c b/contrib/gcclibs/libcpp/files.c index 0e9f97782..366d30ab0 100644 --- a/contrib/gcclibs/libcpp/files.c +++ b/contrib/gcclibs/libcpp/files.c @@ -546,6 +546,7 @@ static bool read_file_guts (cpp_reader *pfile, _cpp_file *file) { ssize_t size, total, count; + off_t offset; uchar *buf; bool regular; @@ -573,6 +574,21 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) } size = file->st.st_size; + + if ((offset = lseek(file->fd, 0, SEEK_CUR)) < 0) + { + cpp_error (pfile, CPP_DL_ERROR, "%s has no current position", + file->path); + return false; + } + else if (offset > INTTYPE_MAXIMUM (ssize_t) || (ssize_t)offset > size) + { + cpp_error (pfile, CPP_DL_ERROR, "current position of %s is too large", + file->path); + return false; + } + + size -= (ssize_t)offset; } else /* 8 kilobytes is a sensible starting size. It ought to be bigger -- 2.45.0