Skip to content

Commit c381523

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 e45b54a commit c381523

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

ext/mysql2/client.c

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

280-
newLen = mysql_escape_string((char *)newStr, StringValuePtr(str), oldLen);
280+
newLen = mysql_escape_string((char *)newStr, RSTRING_PTR(str), oldLen);
281281
if (newLen == oldLen) {
282282
/* no need to return a new ruby string if nothing changed */
283283
xfree(newStr);
@@ -326,12 +326,12 @@ static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE po
326326
VALUE rv;
327327
GET_CLIENT(self);
328328

329-
args.host = NIL_P(host) ? NULL : StringValuePtr(host);
330-
args.unix_socket = NIL_P(socket) ? NULL : StringValuePtr(socket);
329+
args.host = NIL_P(host) ? NULL : StringValueCStr(host);
330+
args.unix_socket = NIL_P(socket) ? NULL : StringValueCStr(socket);
331331
args.port = NIL_P(port) ? 0 : NUM2INT(port);
332-
args.user = NIL_P(user) ? NULL : StringValuePtr(user);
333-
args.passwd = NIL_P(pass) ? NULL : StringValuePtr(pass);
334-
args.db = NIL_P(database) ? NULL : StringValuePtr(database);
332+
args.user = NIL_P(user) ? NULL : StringValueCStr(user);
333+
args.passwd = NIL_P(pass) ? NULL : StringValueCStr(pass);
334+
args.db = NIL_P(database) ? NULL : StringValueCStr(database);
335335
args.mysql = wrapper->client;
336336
args.client_flag = NUM2ULONG(flags);
337337

@@ -663,7 +663,7 @@ static VALUE rb_query(VALUE self, VALUE sql, VALUE current) {
663663
#else
664664
args.sql = sql;
665665
#endif
666-
args.sql_ptr = StringValuePtr(args.sql);
666+
args.sql_ptr = RSTRING_PTR(args.sql);
667667
args.sql_len = RSTRING_LEN(args.sql);
668668
args.wrapper = wrapper;
669669

@@ -717,7 +717,7 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
717717
oldLen = RSTRING_LEN(str);
718718
newStr = xmalloc(oldLen*2+1);
719719

720-
newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, StringValuePtr(str), oldLen);
720+
newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, RSTRING_PTR(str), oldLen);
721721
if (newLen == oldLen) {
722722
/* no need to return a new ruby string if nothing changed */
723723
xfree(newStr);
@@ -781,17 +781,17 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
781781
break;
782782

783783
case MYSQL_READ_DEFAULT_FILE:
784-
charval = (const char *)StringValuePtr(value);
784+
charval = (const char *)StringValueCStr(value);
785785
retval = charval;
786786
break;
787787

788788
case MYSQL_READ_DEFAULT_GROUP:
789-
charval = (const char *)StringValuePtr(value);
789+
charval = (const char *)StringValueCStr(value);
790790
retval = charval;
791791
break;
792792

793793
case MYSQL_INIT_COMMAND:
794-
charval = (const char *)StringValuePtr(value);
794+
charval = (const char *)StringValueCStr(value);
795795
retval = charval;
796796
break;
797797

@@ -961,7 +961,7 @@ static VALUE rb_mysql_client_select_db(VALUE self, VALUE db)
961961
REQUIRE_CONNECTED(wrapper);
962962

963963
args.mysql = wrapper->client;
964-
args.db = StringValuePtr(db);
964+
args.db = StringValueCStr(db);
965965

966966
if (rb_thread_call_without_gvl(nogvl_select_db, &args, RUBY_UBF_IO, 0) == Qfalse)
967967
rb_raise_mysql2_error(wrapper);
@@ -1155,11 +1155,11 @@ static VALUE set_ssl_options(VALUE self, VALUE key, VALUE cert, VALUE ca, VALUE
11551155
GET_CLIENT(self);
11561156

11571157
mysql_ssl_set(wrapper->client,
1158-
NIL_P(key) ? NULL : StringValuePtr(key),
1159-
NIL_P(cert) ? NULL : StringValuePtr(cert),
1160-
NIL_P(ca) ? NULL : StringValuePtr(ca),
1161-
NIL_P(capath) ? NULL : StringValuePtr(capath),
1162-
NIL_P(cipher) ? NULL : StringValuePtr(cipher));
1158+
NIL_P(key) ? NULL : StringValueCStr(key),
1159+
NIL_P(cert) ? NULL : StringValueCStr(cert),
1160+
NIL_P(ca) ? NULL : StringValueCStr(ca),
1161+
NIL_P(capath) ? NULL : StringValueCStr(capath),
1162+
NIL_P(cipher) ? NULL : StringValueCStr(cipher));
11631163

11641164
return self;
11651165
}

ext/mysql2/statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ VALUE rb_mysql_stmt_new(VALUE rb_client, VALUE sql) {
135135
// ensure the string is in the encoding the connection is expecting
136136
args.sql = rb_str_export_to_enc(args.sql, conn_enc);
137137
#endif
138-
args.sql_ptr = StringValuePtr(sql);
138+
args.sql_ptr = RSTRING_PTR(sql);
139139
args.sql_len = RSTRING_LEN(sql);
140140

141141
if ((VALUE)rb_thread_call_without_gvl(nogvl_prepare_statement, &args, RUBY_UBF_IO, 0) == Qfalse) {

0 commit comments

Comments
 (0)