device: Fix device_list_alloc_to_bufs
This commit is contained in:
1 parent
f6c9450319
commit
f8ad95ee4d
1 file changed
+12
-4
+12
-4
@@ -95,6 +95,9 @@ int16_t * hwrevs_alloc_from_string(const char * str) {
|
|||||||
int i;
|
int i;
|
||||||
char buf[5];
|
char buf[5];
|
||||||
|
|
||||||
|
if ( ! str )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
while ( (ptr = strchr(ptr, ',')) ) {
|
while ( (ptr = strchr(ptr, ',')) ) {
|
||||||
++count;
|
++count;
|
||||||
++ptr;
|
++ptr;
|
||||||
@@ -165,8 +168,10 @@ char ** device_list_alloc_to_bufs(const struct device_list * device_list) {
|
|||||||
|
|
||||||
int local = 0;
|
int local = 0;
|
||||||
|
|
||||||
if ( ! device_to_string(device_first->device) )
|
if ( ! device_to_string(device_first->device) ) {
|
||||||
|
device_first = device_first->next;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for ( i = 0; device_first->hwrevs[i] != -1; ++i )
|
for ( i = 0; device_first->hwrevs[i] != -1; ++i )
|
||||||
if ( device_first->hwrevs[i] >= 0 && device_first->hwrevs[i] <= 9999 )
|
if ( device_first->hwrevs[i] >= 0 && device_first->hwrevs[i] <= 9999 )
|
||||||
@@ -181,12 +186,12 @@ char ** device_list_alloc_to_bufs(const struct device_list * device_list) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = calloc(1, count*sizeof(char *) + size);
|
ret = calloc(1, (count+1)*sizeof(char *) + size);
|
||||||
if ( ! ret )
|
if ( ! ret )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
last_ptr = (char *)ret + count*sizeof(char *);
|
last_ptr = (char *)ret + (count+1)*sizeof(char *);
|
||||||
device_first = device_list;
|
device_first = device_list;
|
||||||
|
|
||||||
while ( device_first ) {
|
while ( device_first ) {
|
||||||
@@ -212,12 +217,15 @@ char ** device_list_alloc_to_bufs(const struct device_list * device_list) {
|
|||||||
|
|
||||||
for ( k = 0; k < 30; ++k ) {
|
for ( k = 0; k < 30; ++k ) {
|
||||||
|
|
||||||
|
if ( device_first->hwrevs[i+1] == -1 )
|
||||||
|
break;
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
if ( device_first->hwrevs[i] < 0 || device_first->hwrevs[i] > 9999 )
|
if ( device_first->hwrevs[i] < 0 || device_first->hwrevs[i] > 9999 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
snprintf(ret[j]+1+k*8, 8, "%d", device_first->hwrevs[i]);
|
snprintf(ret[j]+1+16+k*8, 8, "%d", device_first->hwrevs[i]);
|
||||||
last_ptr += 8;
|
last_ptr += 8;
|
||||||
len += 8;
|
len += 8;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user