From 2289acf852fae97d0484304870495b8fc15f752e Mon Sep 17 00:00:00 2001 From: normalperson Date: Thu, 6 Mar 2008 07:41:33 +0000 Subject: ext/http11: remove strchr() and scary comment regarding it Replace it with memchr(3) instead, which works on a buffer with a predetermined length, so we don't have to worry about strange versions of Ruby which don't null-terminate strings. memchr() is used several times in the MRI source code itself (without compatibility definitions), so it should be portable to all platforms MRI runs on. Additionally, we now tolerate null bytes in the Host header and can still parse ports in them correctly if anybody sends them :) If it matters, it is also theoretically faster as it doesn't need to check for a '\0' terminator. git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@993 19e92222-5c0b-0410-8929-a290d50e31e9 --- ext/http11/http11.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/http11/http11.c b/ext/http11/http11.c index 5af1e8c..e0feece 100644 --- a/ext/http11/http11.c +++ b/ext/http11/http11.c @@ -292,8 +292,7 @@ void header_done(void *data, const char *at, size_t length) rb_hash_aset(req, global_gateway_interface, global_gateway_interface_value); if((temp = rb_hash_aref(req, global_http_host)) != Qnil) { - /* ruby better close strings off with a '\0' dammit */ - colon = strchr(RSTRING_PTR(temp), ':'); + colon = memchr(RSTRING_PTR(temp), ':', RSTRING_LEN(temp)); if(colon != NULL) { rb_hash_aset(req, global_server_name, rb_str_substr(temp, 0, colon - RSTRING_PTR(temp))); rb_hash_aset(req, global_server_port, -- cgit v1.2.3-24-ge0c7