From 77eb07cd4391eb452339e7115ed4e74ba779178e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Pinard?= Date: Mon, 18 Feb 2008 19:54:23 -0500 Subject: [PATCH] Compute cursor correctly after realloc --- src/ChangeLog | 5 +++++ src/request.c | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1830617..bb7e762 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -23,6 +23,11 @@ * Makefile.am: Replace lib_LTLIBRARIES by noinst_LIBRARIES. Replace librecode.la by libcode.a and librecode_la by librecode_a. +2001-10-08 Andreas Schwab + + * request.c (guarantee_nul_terminator): Fix bound computation for + realloc. + 2001-07-01 Bruno Haible * task.c (perform_pass_sequence): Call recode_if_nogo before diff --git a/src/request.c b/src/request.c index 9fbcc38..4643c31 100644 --- a/src/request.c +++ b/src/request.c @@ -1,5 +1,5 @@ /* Conversion of files between different charsets and surfaces. - Copyright © 1990,92,93,94,96,97,98,99,00 Free Software Foundation, Inc. + Copyright © 1990,92,93,94,96,97,98,99,00,01 Free Software Foundation, Inc. Contributed by François Pinard , 1990. This library is free software; you can redistribute it and/or @@ -1073,14 +1073,13 @@ guarantee_nul_terminator (RECODE_TASK task) if (task->output.cursor + 4 >= task->output.limit) { RECODE_OUTER outer = task->request->outer; - size_t old_size = task->output.limit - task->output.buffer; - size_t new_size = task->output.cursor + 4 - task->output.buffer; + size_t size = task->output.cursor + 4 - task->output.buffer; /* FIXME: Rethink about how the error should be reported. */ - if (REALLOC (task->output.buffer, new_size, char)) + if (REALLOC (task->output.buffer, size, char)) { - task->output.cursor = task->output.buffer + old_size; - task->output.limit = task->output.buffer + new_size; + task->output.cursor = task->output.buffer + size - 4; + task->output.limit = task->output.buffer + size; } } task->output.cursor[0] = NUL; -- 2.40.0