mirror of
https://github.com/DavidGailleton/42-ft_printf.git
synced 2026-04-28 22:34:34 +02:00
fix: valgrind error when % at end of first printf arg
This commit is contained in:
@@ -10,10 +10,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "ft_printf_bonus.h"
|
#include "ft_printf_bonus.h"
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
static int ft_print_arg_flags(t_arg *arg, va_list args)
|
static int ft_print_arg_flags(t_arg *arg, va_list args)
|
||||||
{
|
{
|
||||||
@@ -84,11 +84,11 @@ int ft_printf(const char *first_arg, ...)
|
|||||||
while (first_arg[i])
|
while (first_arg[i])
|
||||||
{
|
{
|
||||||
temp = nb_print;
|
temp = nb_print;
|
||||||
if (first_arg[i] == '%')
|
if (first_arg[i] == '%' && first_arg[i + 1] != '\0')
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
nb_print += ft_print_arg((char *) &first_arg[i], args);
|
nb_print += ft_print_arg((char *)&first_arg[i], args);
|
||||||
i += ft_to_skip((char *) &first_arg[i]);
|
i += ft_to_skip((char *)&first_arg[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
nb_print += write(1, &first_arg[i], 1);
|
nb_print += write(1, &first_arg[i], 1);
|
||||||
|
|||||||
+2
-2
@@ -10,9 +10,9 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
static int ft_print_arg(char c, va_list args)
|
static int ft_print_arg(char c, va_list args)
|
||||||
{
|
{
|
||||||
@@ -48,7 +48,7 @@ int ft_printf(const char *first_arg, ...)
|
|||||||
while (first_arg[i])
|
while (first_arg[i])
|
||||||
{
|
{
|
||||||
temp = nb_print;
|
temp = nb_print;
|
||||||
if (first_arg[i] == '%')
|
if (first_arg[i] == '%' && first_arg[i + 1] != '\0')
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
nb_print += ft_print_arg(first_arg[i], args);
|
nb_print += ft_print_arg(first_arg[i], args);
|
||||||
|
|||||||
Reference in New Issue
Block a user