Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cef67da9bdaf
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bf6b743aa764
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Sep 26, 2016

  1. Fix: check return value of icon_open

    fixes #3271
    ysbaddaden committed Sep 26, 2016
    Copy the full SHA
    0f5c684 View commit details
  2. Copy the full SHA
    a41a742 View commit details
  3. Merge pull request #3306 from ysbaddaden/core-fix-iconv-error-handling

    Fix iconv error handling
    Ary Borenszweig authored Sep 26, 2016
    Copy the full SHA
    bf6b743 View commit details
Showing with 16 additions and 8 deletions.
  1. +2 −0 src/errno.cr
  2. +14 −8 src/iconv.cr
2 changes: 2 additions & 0 deletions src/errno.cr
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ end
#
# This class is the exception thrown when errno errors are encountered.
class Errno < Exception
# Argument list too long
E2BIG = LibC::E2BIG
# Operation not permitted
EPERM = LibC::EPERM
# No such file or directory
22 changes: 14 additions & 8 deletions src/iconv.cr
Original file line number Diff line number Diff line change
@@ -13,15 +13,19 @@ struct Iconv
to = "#{to}//IGNORE"
end

Errno.value = 0
@iconv = LibC.iconv_open(to, from)
if Errno.value != 0
if original_from == "UTF-8"
raise ArgumentError.new("invalid encoding: #{original_to}")
elsif original_to == "UTF-8"
raise ArgumentError.new("invalid encoding: #{original_from}")

if @iconv.address == LibC::SizeT.new(-1)
if Errno.value == Errno::EINVAL
if original_from == "UTF-8"
raise ArgumentError.new("invalid encoding: #{original_to}")
elsif original_to == "UTF-8"
raise ArgumentError.new("invalid encoding: #{original_from}")
else
raise ArgumentError.new("invalid encoding: #{original_from} -> #{original_to}")
end
else
raise ArgumentError.new("invalid encoding: #{original_from} -> #{original_to}")
raise Errno.new("iconv_open")
end
end
end
@@ -58,6 +62,8 @@ struct Iconv
end

def close
LibC.iconv_close(@iconv)
if LibC.iconv_close(@iconv) == -1
raise Errno.new("iconv_close")
end
end
end