Skip to content

Commit ef87278

Browse files
committed
Convert StringValuePtr to either RSTRING_PTR or StringValueCStr
Where a simple nul-terminated C string is required, use StringValueCStr. Where a string pointer and length are used, follow the pattern: Check_Type(str, T_STRING); ptr = RSTRING_PTR(str); len = RSTRING_LEN(str);
1 parent f182795 commit ef87278

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

ext/mysql2/client.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static VALUE rb_mysql_client_escape(RB_MYSQL_UNUSED VALUE klass, VALUE str) {
287287
oldLen = RSTRING_LEN(str);
288288
newStr = xmalloc(oldLen*2+1);
289289

290-
newLen = mysql_escape_string((char *)newStr, StringValuePtr(str), oldLen);
290+
newLen = mysql_escape_string((char *)newStr, RSTRING_PTR(str), oldLen);
291291
if (newLen == oldLen) {
292292
/* no need to return a new ruby string if nothing changed */
293293
xfree(newStr);
@@ -337,12 +337,12 @@ static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE po
337337
VALUE rv;
338338
GET_CLIENT(self);
339339

340-
args.host = NIL_P(host) ? NULL : StringValuePtr(host);
341-
args.unix_socket = NIL_P(socket) ? NULL : StringValuePtr(socket);
340+
args.host = NIL_P(host) ? NULL : StringValueCStr(host);
341+
args.unix_socket = NIL_P(socket) ? NULL : StringValueCStr(socket);
342342
args.port = NIL_P(port) ? 0 : NUM2INT(port);
343-
args.user = NIL_P(user) ? NULL : StringValuePtr(user);
344-
args.passwd = NIL_P(pass) ? NULL : StringValuePtr(pass);
345-
args.db = NIL_P(database) ? NULL : StringValuePtr(database);
343+
args.user = NIL_P(user) ? NULL : StringValueCStr(user);
344+
args.passwd = NIL_P(pass) ? NULL : StringValueCStr(pass);
345+
args.db = NIL_P(database) ? NULL : StringValueCStr(database);
346346
args.mysql = wrapper->client;
347347
args.client_flag = NUM2ULONG(flags);
348348

@@ -669,7 +669,7 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
669669
/* ensure the string is in the encoding the connection is expecting */
670670
args.sql = rb_str_export_to_enc(args.sql, conn_enc);
671671
#endif
672-
args.sql_ptr = StringValuePtr(args.sql);
672+
args.sql_ptr = RSTRING_PTR(args.sql);
673673
args.sql_len = RSTRING_LEN(args.sql);
674674

675675
/* see if this connection is still waiting on a result from a previous query */
@@ -736,7 +736,7 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
736736
oldLen = RSTRING_LEN(str);
737737
newStr = xmalloc(oldLen*2+1);
738738

739-
newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, StringValuePtr(str), oldLen);
739+
newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, RSTRING_PTR(str), oldLen);
740740
if (newLen == oldLen) {
741741
/* no need to return a new ruby string if nothing changed */
742742
xfree(newStr);
@@ -800,17 +800,17 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
800800
break;
801801

802802
case MYSQL_READ_DEFAULT_FILE:
803-
charval = (const char *)StringValuePtr(value);
803+
charval = (const char *)StringValueCStr(value);
804804
retval = charval;
805805
break;
806806

807807
case MYSQL_READ_DEFAULT_GROUP:
808-
charval = (const char *)StringValuePtr(value);
808+
charval = (const char *)StringValueCStr(value);
809809
retval = charval;
810810
break;
811811

812812
case MYSQL_INIT_COMMAND:
813-
charval = (const char *)StringValuePtr(value);
813+
charval = (const char *)StringValueCStr(value);
814814
retval = charval;
815815
break;
816816

@@ -987,7 +987,7 @@ static VALUE rb_mysql_client_select_db(VALUE self, VALUE db)
987987
REQUIRE_CONNECTED(wrapper);
988988

989989
args.mysql = wrapper->client;
990-
args.db = StringValuePtr(db);
990+
args.db = StringValueCStr(db);
991991

992992
if (rb_thread_call_without_gvl(nogvl_select_db, &args, RUBY_UBF_IO, 0) == Qfalse)
993993
rb_raise_mysql2_error(wrapper);
@@ -1183,11 +1183,11 @@ static VALUE set_ssl_options(VALUE self, VALUE key, VALUE cert, VALUE ca, VALUE
11831183
GET_CLIENT(self);
11841184

11851185
mysql_ssl_set(wrapper->client,
1186-
NIL_P(key) ? NULL : StringValuePtr(key),
1187-
NIL_P(cert) ? NULL : StringValuePtr(cert),
1188-
NIL_P(ca) ? NULL : StringValuePtr(ca),
1189-
NIL_P(capath) ? NULL : StringValuePtr(capath),
1190-
NIL_P(cipher) ? NULL : StringValuePtr(cipher));
1186+
NIL_P(key) ? NULL : StringValueCStr(key),
1187+
NIL_P(cert) ? NULL : StringValueCStr(cert),
1188+
NIL_P(ca) ? NULL : StringValueCStr(ca),
1189+
NIL_P(capath) ? NULL : StringValueCStr(capath),
1190+
NIL_P(cipher) ? NULL : StringValueCStr(cipher));
11911191

11921192
return self;
11931193
}

0 commit comments

Comments
 (0)