fix: check argument overflow

This commit is contained in:
Camille Chauvet 2023-04-19 13:51:57 +00:00
parent f19a96a233
commit 23e8774c44

View File

@ -6,21 +6,28 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 14:43:33 by cchauvet #+# #+# */ /* Created: 2023/03/08 14:43:33 by cchauvet #+# #+# */
/* Updated: 2023/04/11 14:47:30 by cchauvet ### ########.fr */ /* Updated: 2023/04/19 13:49:58 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../philo.h" #include "../philo.h"
#include <stddef.h>
#include <limits.h>
bool ft_isnum(char str[]) bool ft_isnum(char str[])
{ {
size_t i; size_t i;
size_t num;
num = 0;
i = 0; i = 0;
while (str[i] != '\0') while (str[i] != '\0')
{ {
if (str[i] > '9' || str[i] < '0') if (str[i] > '9' || str[i] < '0')
return (0); return (0);
num = num * 10 + str[i] - 48;
if (num > INT_MAX)
return (0);
i++; i++;
} }
return (1); return (1);