aboutsummaryrefslogtreecommitdiff
path: root/ft_substr.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-17 09:09:41 +0200
committerCharles <sircharlesaze@gmail.com>2019-10-17 09:09:41 +0200
commit6cb01d2fd8a6b07ef3ddaa8bb322f30c545316e7 (patch)
treeb4ff52e57f5cbef2a4ea578e0401a2b206318d4a /ft_substr.c
parent8a4d4c806e9896228f016baa62c5c7e219acf655 (diff)
downloadlibft-6cb01d2fd8a6b07ef3ddaa8bb322f30c545316e7.tar.gz
libft-6cb01d2fd8a6b07ef3ddaa8bb322f30c545316e7.tar.bz2
libft-6cb01d2fd8a6b07ef3ddaa8bb322f30c545316e7.zip
More protection
- substr if start > str length - all list functions check for NULL reference - not modifying const pointers
Diffstat (limited to 'ft_substr.c')
-rw-r--r--ft_substr.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ft_substr.c b/ft_substr.c
index 1d22059..1c23e85 100644
--- a/ft_substr.c
+++ b/ft_substr.c
@@ -1,22 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_strsub.c :+: :+: :+: */
+/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/07 10:16:26 by cacharle #+# #+# */
-/* Updated: 2019/10/14 13:24:02 by cacharle ### ########.fr */
+/* Created: 2019/10/17 08:28:49 by cacharle #+# #+# */
+/* Updated: 2019/10/17 08:28:55 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
+#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
unsigned int i;
char *sub;
+ if (start > ft_strlen(s))
+ return (NULL);
if ((sub = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
return (NULL);
i = 0;