summaryrefslogtreecommitdiffstats
path: root/lib/curl_memrchr.c
diff options
context:
space:
mode:
authorCurl Upstream <curl-library@cool.haxx.se>2018-05-15 14:43:56 (GMT)
committerBrad King <brad.king@kitware.com>2018-05-18 14:16:12 (GMT)
commitd431136e029c652f5913bcebeaab3b9236b114c4 (patch)
treec0838b4432a3786a323c94a680bb16f644198311 /lib/curl_memrchr.c
parentaf9e654045f11028e50dac4781e297834129a749 (diff)
downloadCMake-d431136e029c652f5913bcebeaab3b9236b114c4.zip
CMake-d431136e029c652f5913bcebeaab3b9236b114c4.tar.gz
CMake-d431136e029c652f5913bcebeaab3b9236b114c4.tar.bz2
curl 2018-05-15 (cb013830)
Code extracted from: https://github.com/curl/curl.git at commit cb013830383f1ccc9757aba36bc32df5ec281c02 (curl-7_60_0).
Diffstat (limited to 'lib/curl_memrchr.c')
-rw-r--r--lib/curl_memrchr.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/curl_memrchr.c b/lib/curl_memrchr.c
index c521497..eeb3044 100644
--- a/lib/curl_memrchr.c
+++ b/lib/curl_memrchr.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -44,17 +44,18 @@
void *
Curl_memrchr(const void *s, int c, size_t n)
{
- const unsigned char *p = s;
- const unsigned char *q = s;
+ if(n > 0) {
+ const unsigned char *p = s;
+ const unsigned char *q = s;
- p += n - 1;
+ p += n - 1;
- while(p >= q) {
- if(*p == (unsigned char)c)
- return (void *)p;
- p--;
+ while(p >= q) {
+ if(*p == (unsigned char)c)
+ return (void *)p;
+ p--;
+ }
}
-
return NULL;
}