mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 01:05:54 +08:00
strstr fails because length off by 1
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2022 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+3
-3
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* lib/lib_strncmp.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -52,10 +52,10 @@
|
||||
#ifndef CONFIG_ARCH_STRNCMP
|
||||
int strncmp(const char *cs, const char *ct, size_t nb)
|
||||
{
|
||||
register signed char result = 0;
|
||||
int result = 0;
|
||||
for (; nb > 0; nb--)
|
||||
{
|
||||
if ((result = *cs - *ct++) != 0 || !*cs++)
|
||||
if ((result = (int)*cs - (int)*ct++) != 0 || !*cs++)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
+3
-3
@@ -53,7 +53,9 @@ char *strstr(const char *str, const char *substr)
|
||||
|
||||
/* Special case the empty substring */
|
||||
|
||||
ch = *substr++;
|
||||
len = strlen(substr);
|
||||
ch = *substr++;
|
||||
|
||||
if (!ch)
|
||||
{
|
||||
/* We'll say that an empty substring matches at the beginning of
|
||||
@@ -66,8 +68,6 @@ char *strstr(const char *str, const char *substr)
|
||||
/* Search for the substring */
|
||||
|
||||
candidate = str;
|
||||
len = strlen(substr);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* strchr() will return a pointer to the next occurrence of the
|
||||
|
||||
Reference in New Issue
Block a user