printf-hook-builtin: Correctly calculate written bytes in print_in_hook()
[strongswan.git] / src / libstrongswan / utils / printf_hook / printf_hook_builtin.c
index 7ed3979..c79d4b8 100644 (file)
@@ -122,10 +122,14 @@ size_t print_in_hook(printf_hook_data_t *data, char *fmt, ...)
 
        if (written > data->n)
        {
-               written = data->n;
+               data->q += data->n;
+               data->n = 0;
+       }
+       else
+       {
+               data->q += written;
+               data->n -= written;
        }
-       data->q += written;
-       data->n += written;
        return written;
 }