[LLVMbugs] [Bug 17358] New: raw_ostream.write fails to account for when buffer size is larger than INT_MAX
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Sep 25 06:45:29 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=17358
Bug ID: 17358
Summary: raw_ostream.write fails to account for when buffer
size is larger than INT_MAX
Product: libraries
Version: trunk
Hardware: PC
OS: FreeBSD
Status: NEW
Severity: normal
Priority: P
Component: Support Libraries
Assignee: unassignedbugs at nondot.org
Reporter: khilan.gudka at cl.cam.ac.uk
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Dear all
FreeBSD has a restriction that the write() system call can only write up to
INT_MAX (~2GB) bytes and will otherwise return errno 22 (EINVAL).
Adding this code to the start of write(const char *Ptr, size_t Size) in
lib/Support/raw_ostream.cpp seems to do the trick:
#ifdef __FreeBSD__
if (LLVM_UNLIKELY(Size > INT_MAX)) {
write(Ptr, INT_MAX);
return write(Ptr + INT_MAX, Size - INT_MAX);
}
#endif
I'm not sure what would be a suitable test case for this except that the
following code will tell you if your particular platform can/cannot write more
than INT_MAX:
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#define BUF_SIZE 2147483648
char arr[BUF_SIZE];
int main(int argc, char** argv) {
unsigned int i;
for (i=0; i<BUF_SIZE; i++) {
arr[i] = 3;
}
int fd = open("dump.txt", O_CREAT | O_RDWR);
int ret = write(fd, arr, BUF_SIZE);
if (ret < 0) {
printf("Error writing: %d\n", errno);
}
close(fd);
return 0;
}
Regards
Khilan
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130925/d0644e93/attachment.html>
More information about the llvm-bugs
mailing list