1 From 4d373ffcfee6853662421370fad3df3701573712 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Thu, 7 Jan 2016 12:49:51 +0100
4 Subject: [PATCH lxcfs 4/5] cgfs: fix dorealloc's batch allocation
6 The initial check should use real lengths as with modulo a
7 new required length of eg. 52 would be considered smaller
8 than an old length of 48 (2 < 48).
10 To get the 'batches' count 'newlen' must be divided and not
11 taken modulo BATCH_SIZE. Otherwise '101', which would need a
12 3rd batch to reach 150, would end up with two (2*50 = 100
13 bytes) and thereby be truncated instead.
15 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
18 1 file changed, 2 insertions(+), 2 deletions(-)
20 diff --git a/cgfs.c b/cgfs.c
21 index 0659e9e..681a478 100644
24 @@ -75,9 +75,9 @@ static inline void drop_trailing_newlines(char *s)
25 static void dorealloc(char **mem, size_t oldlen, size_t newlen)
28 - if (newlen % BATCH_SIZE <= oldlen % BATCH_SIZE)
29 + if (newlen <= oldlen)
31 - batches = (newlen % BATCH_SIZE) + 1;
32 + batches = (newlen / BATCH_SIZE) + 1;
35 *mem = malloc(batches * BATCH_SIZE);