[lxc-devel] [PATCH lxcfs 4/5] cgfs: fix dorealloc's batch allocation
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Jan 7 11:59:54 UTC 2016
The initial check should use real lengths as with modulo a
new required length of eg. 52 would be considered smaller
than an old length of 48 (2 < 48).
To get the 'batches' count 'newlen' must be divided and not
taken modulo BATCH_SIZE. Otherwise '101', which would need a
3rd batch to reach 150, would end up with two (2*50 = 100
bytes) and thereby be truncated instead.
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
cgfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cgfs.c b/cgfs.c
index 0659e9e..681a478 100644
--- a/cgfs.c
+++ b/cgfs.c
@@ -75,9 +75,9 @@ static inline void drop_trailing_newlines(char *s)
static void dorealloc(char **mem, size_t oldlen, size_t newlen)
{
int batches;
- if (newlen % BATCH_SIZE <= oldlen % BATCH_SIZE)
+ if (newlen <= oldlen)
return;
- batches = (newlen % BATCH_SIZE) + 1;
+ batches = (newlen / BATCH_SIZE) + 1;
if (!*mem) {
do {
*mem = malloc(batches * BATCH_SIZE);
--
2.1.4
More information about the lxc-devel
mailing list