Open Bug 617921 Opened 9 years ago Updated 2 years ago

Snarf should pass a positive value to fread

Categories

(Core :: JavaScript Engine, defect)

x86
Windows 7
defect
Not set

Tracking

()

ASSIGNED

People

(Reporter: timeless, Assigned: timeless)

References

(Blocks 1 open bug, )

Details

(Keywords: coverity, Whiteboard: [needs new patch])

Attachments

(1 obsolete file)

4081 Snarf(JSContext *cx, uintN argc, jsval *vp)
4082 {

4115     file = fopen(pathname, "rb");
4122             len = ftell(file);
4123             if (fseek(file, 0, SEEK_SET) == EOF) {
4124                 JS_ReportError(cx, "can't seek start of %s", pathname);
4125             } else {
4126                 buf = (char*) JS_malloc(cx, len + 1);
4127                 if (buf) {
4128                     cc = fread(buf, 1, len, file);

1. ftell can return -1 on failure, this should be checked.
2. fread wants a size_t, not an ssize_t, so once 1 is done, we can cast to size_t
Summary: Snarf should pass an unsigned value to fread → Snarf should pass a positive value to fread
Assignee: general → timeless
Status: NEW → ASSIGNED
Attachment #496584 - Flags: review?(jorendorff)
Attachment #496584 - Flags: review?(jorendorff) → review+
http://msdn.microsoft.com/en-us/library/0ys3hc0b(VS.71).aspx

long ftell( 
   FILE *stream 
);

I wonder if ssize_t is close enough to long that I could use long on all platforms.
OS: Mac OS X → Windows 7
Keywords: checkin-needed
timeless: I'm confused as to how this is checkin-needed? AFAICT, there hasn't been a patch since the backout?
Keywords: checkin-needed
Whiteboard: [needs new patch]
Attachment #496584 - Attachment description: patch → patch [doesn't compile on Windows]
Attachment #496584 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.