R
R
Robotex2011-03-07 05:08:33
C++ / C#
Robotex, 2011-03-07 05:08:33

Resizing a static array (with data loss)?

Take a look at the structure struct fp_print_data

enum fp_print_data_type {
        PRINT_DATA_RAW = 0, /* memset-imposed default */
        PRINT_DATA_NBIS_MINUTIAE,
};
 
struct fp_print_data {
        uint16_t driver_id;
        uint32_t devtype;
        enum fp_print_data_type type;
        size_t length;
        unsigned char data[0];  // Здесь массив из одного элемента
};

But when I scan the fingerprint, the size of this array is 2404 bytes. How does it change its size?
I am porting libfprint (these structures are taken from there unchanged) to qt4 and I need to transform this structure into QByteArray and back. I've successfully written data to byteArray, but I'm having a hard time doing the reverse. Take a look at the function:
struct fp_print_data CFingerprintScanner::byteArrayToFpdata(QByteArray byteArray)
{
    quint16 driver_id;
    quint32 devtype;
    quint32 type;
    quint64 length;
    char * data;
 
    struct fp_print_data fpdata;
 
    QBuffer buffer(&byteArray);
    buffer.open(QIODevice::ReadOnly);
 
    QDataStream in(&buffer);
 
    in >> driver_id;
    in >> devtype;
    in >> type;
    in >> length;
 
    data = (char *) malloc(length);
 
    in.readRawData(data, length);
 
    fpdata.driver_id = (uint16_t) driver_id;
    fpdata.devtype = (uint32_t) devtype;
    fpdata.type = (enum fp_print_data_type) type;
    fpdata.length = (size_t) length;
 
    // вот здесь мне нужно записать data в fpdata.data, но как это можно сделать?
    // ведь невозможно преобразовать char * (или unsigned char*) в unsigned char[0]
    // я перерыл всю библиотеку, но не нашел места, в котором они делают такое преобразование
 
    free(data);
 
    return fpdata;
}

I'm at a loss. Can anyone explain to me how to write a large amount of data to that array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_one, 2011-03-07
@al_one

struct fp_print_data *CFingerprintScanner::byteArrayToFpdata(QByteArray byteArray)
{
return (struct fp_print_data *)byteArray.data();
}

(But you need to watch the lifetime of byteArray).
If I were you, I would assign this job to another person who is more familiar with programming.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question