From d5b967eb52d70a459dc85416328a43cefeeed749 Mon Sep 17 00:00:00 2001 From: Dustin Sallings Date: Sun, 26 Sep 2010 12:37:38 -0700 Subject: [PATCH] No need to scan a whole string to see if the first char is null. Change-Id: I5eba2350e3c21ad8bde4194e6ef828bc8e1e5f25 Reviewed-on: http://review.northscale.com/2737 Reviewed-by: Chiyoung Seo Tested-by: Chiyoung Seo --- bucket_engine.c | 2 +- testapp.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bucket_engine.c b/bucket_engine.c index 1019635..df3b8b4 100644 --- a/bucket_engine.c +++ b/bucket_engine.c @@ -350,7 +350,7 @@ static proxied_engine_handle_t* retain_handle(proxied_engine_handle_t *peh) { } static bool has_valid_bucket_name(const char *n) { - bool rv = strlen(n) > 0; + bool rv = n[0] != 0; for (; *n; n++) { rv &= isalpha(*n) || isdigit(*n) || *n == '.' || *n == '%' || *n == '_' || *n == '-'; } diff --git a/testapp.c b/testapp.c index f0bc012..f6519c0 100644 --- a/testapp.c +++ b/testapp.c @@ -780,6 +780,12 @@ static enum test_result test_bucket_name_validation(ENGINE_HANDLE *h, assert(rv == ENGINE_SUCCESS); assert(last_status == PROTOCOL_BINARY_RESPONSE_NOT_STORED); + pkt = create_create_bucket_pkt("", ENGINE_PATH, ""); + rv = h1->unknown_command(h, mk_conn("admin", NULL), pkt, add_response); + free(pkt); + assert(rv == ENGINE_SUCCESS); + assert(last_status == PROTOCOL_BINARY_RESPONSE_NOT_STORED); + return SUCCESS; }