Answer the question
In order to leave comments, you need to log in
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]; // Здесь массив из одного элемента
};
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;
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question