Skip to content

Commit

Permalink
Ensure string options are converted to proper strings before passing …
Browse files Browse the repository at this point in the history
…to ccall (#204)

Proper fix to #201. The core issue here is that if you take the `pointer` of a SubString,
it doesn't properly account for the _substring_ length, because C strings continue
until the NUL termination.
  • Loading branch information
quinnj authored Oct 25, 2022
1 parent a8ae1c7 commit 2c15d97
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/api/capi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -964,14 +964,20 @@ For more information about option files used by MySQL programs, see Section 4.2.
function setoption(mysql::MYSQL, option::mysql_option, arg="0")
if option in CUINTOPTS
ref = Ref{Cuint}(Cuint(arg))
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
elseif option in CULONGOPTS
ref = Ref{Culong}(Culong(arg))
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
elseif option in BOOLOPTS
ref = Ref{Bool}(Bool(arg))
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
else
ref = arg == C_NULL ? C_NULL : convert(Ptr{Cvoid}, pointer(arg))
str = arg == C_NULL ? C_NULL : String(arg)
GC.@preserve str begin
ref = str == C_NULL ? C_NULL : convert(Ptr{Cvoid}, pointer(str))
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
end
end
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
end

#="""
Expand Down

0 comments on commit 2c15d97

Please sign in to comment.