mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
bitmap: fix problems in previous commit
Commit ee3d3893 missed the fact that (unsigned char)<<(int) is truncated to int, and therefore failed for any bitmap data longer than four bytes. Also, I failed to run 'make syntax-check' on my commit 4bba6579; for whatever odd reason, ffs lives in a different header than ffsl. * src/util/bitmap.c (virBitmapNewData): Use correct shift type. (includes): Glibc (and therefore gnulib) decided ffs is in <strings.h>, but ffsl is in <string.h>. * tests/virbitmaptest.c (test5): Test it.
This commit is contained in:
parent
4bba6579cc
commit
fd66ea669c
@ -27,7 +27,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
@ -434,7 +433,7 @@ virBitmapPtr virBitmapNewData(void *data, int len)
|
|||||||
j = 0;
|
j = 0;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*p |= bytes[i] << (j * CHAR_BIT);
|
*p |= (unsigned long) bytes[i] << (j * CHAR_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
@ -214,15 +214,15 @@ error:
|
|||||||
/* test for virBitmapNewData/ToData */
|
/* test for virBitmapNewData/ToData */
|
||||||
static int test5(const void *v ATTRIBUTE_UNUSED)
|
static int test5(const void *v ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
char data[] = {0x01, 0x02, 0x00, 0x00};
|
char data[] = {0x01, 0x02, 0x00, 0x00, 0x04};
|
||||||
unsigned char *data2 = NULL;
|
unsigned char *data2 = NULL;
|
||||||
int len2;
|
int len2;
|
||||||
int bits[] = {0, 9};
|
int bits[] = {0, 9, 34};
|
||||||
virBitmapPtr bitmap;
|
virBitmapPtr bitmap;
|
||||||
int i, j;
|
int i, j;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
bitmap = virBitmapNewData(data, 4);
|
bitmap = virBitmapNewData(data, sizeof(data));
|
||||||
if (!bitmap)
|
if (!bitmap)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -242,10 +242,12 @@ static int test5(const void *v ATTRIBUTE_UNUSED)
|
|||||||
if (virBitmapToData(bitmap, &data2, &len2) < 0)
|
if (virBitmapToData(bitmap, &data2, &len2) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (data2[0] != 0x05 ||
|
if (len2 != sizeof(data) ||
|
||||||
|
data2[0] != 0x05 ||
|
||||||
data2[1] != 0x82 ||
|
data2[1] != 0x82 ||
|
||||||
data2[2] != 0x00 ||
|
data2[2] != 0x00 ||
|
||||||
data2[3] != 0x00)
|
data2[3] != 0x00 ||
|
||||||
|
data2[4] != 0x04)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user