You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/05/10 13:51:52 UTC
[GitHub] [incubator-nuttx] juniskane commented on a diff in pull request #6229: libc/string: simplify strrchr
juniskane commented on code in PR #6229:
URL: https://github.com/apache/incubator-nuttx/pull/6229#discussion_r869267336
##########
libs/libc/string/lib_strrchr.c:
##########
@@ -37,15 +37,16 @@
#undef strrchr /* See mm/README.txt */
FAR char *strrchr(FAR const char *s, int c)
{
- FAR const char *p = &s[strlen(s)];
+ FAR const char *r = NULL;
- for (; p >= s; p--)
+ do
{
- if (*p == c)
+ if (*s == (char)c)
{
- return (FAR char *)p;
+ r = s;
}
}
+ while (*s++);
Review Comment:
done
##########
libs/libc/string/lib_strrchr.c:
##########
@@ -37,15 +37,16 @@
#undef strrchr /* See mm/README.txt */
FAR char *strrchr(FAR const char *s, int c)
{
- FAR const char *p = &s[strlen(s)];
+ FAR const char *r = NULL;
- for (; p >= s; p--)
+ do
{
- if (*p == c)
+ if (*s == (char)c)
Review Comment:
removed cast
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org