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/07/21 14:24:52 UTC

[GitHub] [incubator-nuttx] Cynerd opened a new pull request, #6667: libs/libc/string: add memmem

Cynerd opened a new pull request, #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667

   This function is the GNU extension.
   
   ## Summary
   
   ## Impact
   
   ## Testing
   
   Tested on custom SAME70N21 based board.
   
   


-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#issuecomment-1191616583

   @Cynerd let's squash these patch into one.


-- 
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


[GitHub] [incubator-nuttx] pkarashchenko commented on pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#issuecomment-1191882072

   Please fix build error
   ```
   string/lib_memmem.c: In function 'memmem':
   Error: string/lib_memmem.c:65:24: error: return discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
      65 |               return h + i;
   ```


-- 
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


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#discussion_r926748603


##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,
+                  FAR const void *needle, size_t needlelen)
+{
+  size_t i, y;
+  const unsigned char *h = haystack;
+  const unsigned char *n = needle;
+
+  if (needlelen > haystacklen)
+    return NULL;
+
+  for (i = 0; i < (haystacklen - needlelen); i++)
+    {
+      y = 0;
+      while (h[i + y] == n[y])
+      {

Review Comment:
   run checkpatch.sh to check



-- 
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


[GitHub] [incubator-nuttx] pkarashchenko merged pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
pkarashchenko merged PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667


-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#discussion_r926787125


##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,
+                  FAR const void *needle, size_t needlelen)
+{
+  size_t i;
+  size_t y;

Review Comment:
   move i and y after line 51?



##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,
+                  FAR const void *needle, size_t needlelen)
+{
+  size_t i;
+  size_t y;
+  FAR const unsigned char *h = haystack;
+  FAR const unsigned char *n = needle;
+
+  if (needlelen > haystacklen)
+    {
+      return NULL;
+    }
+
+  for (i = 0; i < (haystacklen - needlelen); i++)

Review Comment:
   remove () around haystacklen - needlelen?



##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,

Review Comment:
   remove extra space before *



-- 
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


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#discussion_r926747539


##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>

Review Comment:
   remove



##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,
+                  FAR const void *needle, size_t needlelen)
+{
+  size_t i, y;
+  const unsigned char *h = haystack;

Review Comment:
   add FAR,ditto



-- 
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


[GitHub] [incubator-nuttx] Cynerd commented on a diff in pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#discussion_r926757085


##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,
+                  FAR const void *needle, size_t needlelen)
+{
+  size_t i, y;
+  const unsigned char *h = haystack;
+  const unsigned char *n = needle;
+
+  if (needlelen > haystacklen)
+    return NULL;
+
+  for (i = 0; i < (haystacklen - needlelen); i++)
+    {
+      y = 0;
+      while (h[i + y] == n[y])
+      {

Review Comment:
   Oh.. my fault. I used invalid argument to run checkpatch.sh... :angel: 
   



##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,
+                  FAR const void *needle, size_t needlelen)
+{
+  size_t i, y;
+  const unsigned char *h = haystack;

Review Comment:
   Added... good point.



-- 
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


[GitHub] [incubator-nuttx] Cynerd commented on a diff in pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#discussion_r926757897


##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>

Review Comment:
   I copied it from other files, but it is true that it is not necessary here at all.



-- 
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


[GitHub] [incubator-nuttx] Cynerd commented on a diff in pull request #6667: libs/libc/string: add memmem

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #6667:
URL: https://github.com/apache/incubator-nuttx/pull/6667#discussion_r926827355


##########
libs/libc/string/lib_memmem.c:
##########
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * libs/libc/string/lib_memmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: memmem
+ *
+ * Description:
+ *   The memmem() function finds the start of the first occurrence of the
+ *   substring needle of length needlelen in the memory area haystack of
+ *   length haystacklen.
+ *
+ * Returned Value:
+ *   The memmem() function returns a pointer to the beginning of the
+ *   substring, or NULL if the substring is not found.
+ *
+ ****************************************************************************/
+
+FAR void  *memmem(FAR const void *haystack, size_t haystacklen,
+                  FAR const void *needle, size_t needlelen)
+{
+  size_t i;
+  size_t y;
+  FAR const unsigned char *h = haystack;
+  FAR const unsigned char *n = needle;
+
+  if (needlelen > haystacklen)
+    {
+      return NULL;
+    }
+
+  for (i = 0; i < (haystacklen - needlelen); i++)

Review Comment:
   Honestly, I am used to adding them when math gets long but not necessary here for sure.



-- 
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