Skip to content

Commit 2c15d97

Browse files
authored
Ensure string options are converted to proper strings before passing 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.
1 parent a8ae1c7 commit 2c15d97

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/api/capi.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -964,14 +964,20 @@ For more information about option files used by MySQL programs, see Section 4.2.
964964
function setoption(mysql::MYSQL, option::mysql_option, arg="0")
965965
if option in CUINTOPTS
966966
ref = Ref{Cuint}(Cuint(arg))
967+
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
967968
elseif option in CULONGOPTS
968969
ref = Ref{Culong}(Culong(arg))
970+
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
969971
elseif option in BOOLOPTS
970972
ref = Ref{Bool}(Bool(arg))
973+
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
971974
else
972-
ref = arg == C_NULL ? C_NULL : convert(Ptr{Cvoid}, pointer(arg))
975+
str = arg == C_NULL ? C_NULL : String(arg)
976+
GC.@preserve str begin
977+
ref = str == C_NULL ? C_NULL : convert(Ptr{Cvoid}, pointer(str))
978+
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
979+
end
973980
end
974-
return @checksuccess mysql mysql_options(mysql.ptr, option, ref)
975981
end
976982

977983
#="""

0 commit comments

Comments
 (0)