Skip to content

Commit

Permalink
mop up more 32-bit checked int conversion bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nolta committed Oct 5, 2014
1 parent 9134b47 commit 9ade6e5
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ for to in tuple(IntTypes...,Char), from in tuple(IntTypes...,Char,Bool)
else
@eval convert(::Type{$to}, x::($from)) = box($to,zext_int($to,unbox($from,x)))
end
elseif !(issubtype(from,Signed) === issubtype(to,Signed))
# raise InexactError if x's top bit is set
@eval convert(::Type{$to}, x::($from)) = box($to,check_top_bit(unbox($from,x)))
@eval itrunc(::Type{$to}, x::($from)) = box($to,unbox($from,x))
else
@eval convert(::Type{$to}, x::($from)) = box($to,unbox($from,x))
if !(issubtype(from,Signed) === issubtype(to,Signed))
# raise InexactError if x's top bit is set
@eval convert(::Type{$to}, x::($from)) = box($to,check_top_bit(unbox($from,x)))
else
@eval convert(::Type{$to}, x::($from)) = box($to,unbox($from,x))
end
@eval itrunc(::Type{$to}, x::($from)) = box($to,unbox($from,x))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function mmap(len::Integer, prot::Integer, flags::Integer, fd, offset::Integer)
len_page::Int = (offset-offset_page) + len
# Mmap the file
p = ccall(:jl_mmap, Ptr{Void}, (Ptr{Void}, Csize_t, Cint, Cint, Cint, FileOffset), C_NULL, len_page, prot, flags, fd, offset_page)
systemerror("memory mapping failed", int(p) == -1)
systemerror("memory mapping failed", reinterpret(Int,p) == -1)
# Also return a pointer that compensates for any adjustment in the offset
return p, int(offset-offset_page)
end
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function intersect(A::VersionSet, B::VersionSet)
VersionSet(ivals)
end
==(A::VersionSet, B::VersionSet) = A.intervals == B.intervals
hash(s::VersionSet, h::Uint) = hash(s.intervals, h + uint(0x2fd2ca6efa023f44))
hash(s::VersionSet, h::Uint) = hash(s.intervals, h + itrunc(Uint,0x2fd2ca6efa023f44))
deepcopy_internal(vs::VersionSet, ::ObjectIdDict) = VersionSet(copy(vs.intervals))

typealias Requires Dict{ByteString,VersionSet}
Expand Down
2 changes: 1 addition & 1 deletion base/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const UNKNOWN = LineInfo("?", "?", -1, true, 0)
==(a::LineInfo, b::LineInfo) = a.line == b.line && a.fromC == b.fromC && a.func == b.func && a.file == b.file

function hash(li::LineInfo, h::Uint)
h += uint(0xf4fbda67fe20ce88)
h += itrunc(Uint,0xf4fbda67fe20ce88)
h = hash(li.line, h)
h = hash(li.file, h)
h = hash(li.func, h)
Expand Down
2 changes: 1 addition & 1 deletion base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ function print_escaped(io, s::String, esc::String)
c == '\e' ? print(io, "\\e") :
c == '\\' ? print(io, "\\\\") :
c in esc ? print(io, '\\', c) :
7 <= c <= 13 ? print(io, '\\', "abtnvfr"[int(c-6)]) :
'\a' <= c <= '\r' ? print(io, '\\', "abtnvfr"[int(c)-6]) :
isprint(c) ? print(io, c) :
c <= '\x7f' ? print(io, "\\x", hex(c, 2)) :
c <= '\uffff' ? print(io, "\\u", hex(c, need_full_hex(s,j) ? 4 : 2)) :
Expand Down
2 changes: 1 addition & 1 deletion base/utf8proc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export normalize_string, is_valid_char, is_assigned_char,
iscntrl, ispunct, isspace, isprint, isgraph, isblank

# whether codepoints are valid Unicode
is_valid_char(c) = (0 <= c <= 0x110000) && bool(ccall(:utf8proc_codepoint_valid, Cuchar, (Int32,), c))
is_valid_char(c) = (0x0 <= c <= 0x110000) && bool(ccall(:utf8proc_codepoint_valid, Cuchar, (Int32,), c))

# utf8 category constants
const UTF8PROC_CATEGORY_LU = 1
Expand Down
2 changes: 1 addition & 1 deletion base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function isless(a::VersionNumber, b::VersionNumber)
end

function hash(v::VersionNumber, h::Uint)
h += uint(0x8ff4ffdb75f9fede)
h += itrunc(Uint,0x8ff4ffdb75f9fede)
h = hash(v.major, h)
h = hash(v.minor, h)
h = hash(v.patch, h)
Expand Down

0 comments on commit 9ade6e5

Please sign in to comment.