An error sometimes occurs during program running.
It doesn't happen every time.
I don't know why I get an error in this part.
The length of strAckData is greater than 13
x_FWCommunity->sRevDataStr = strAckData.GetAt(13); '
User SourceCode
void CMLT2App::AckTotalFusingMsg(CString strAckData)
{
char szLog[512];
CString strCmd(""), strResult(""), strTemp(""), strLen("");
char cResult;
int nCmd = 0, nPos = 0, nDataLen = 0;
strTemp = strAckData;
nPos = strTemp.Find(0x02);
strAckData = strTemp.Mid(nPos, strAckData.GetLength() - nPos);
if (strAckData.GetAt(0) != 0x02) return; // Check STX
if (strAckData.GetAt((strAckData.GetLength() - 1)) != 0x03) // Check ETX
return;
strCmd.Format("%s", strAckData.Mid(7, 2)); // Get Command;
sscanf(strCmd, "%X", &nCmd); // String Convert to Hex
cResult = strAckData.GetAt(13); // String Convert to Decimal
x_FWCommunity->sRevCmdStr = strCmd;
strLen.Format("%s", strAckData.Mid(9, 4));
sscanf(strLen, "%X", &nDataLen);
// strCmd 는 0xBD
if (strCmd == "FE" || strCmd == "5E")
{
x_FWCommunity->sRevDataStr = strAckData.Mid(13, nDataLen);
// AfxMessageBox(x_FWCommunity->sRevDataStr);
}
else
x_FWCommunity->sRevDataStr = strAckData.GetAt(13); ← Error Point
switch (nCmd)
{
case CMD_CTRL_FUSING_SYSTEM:
case CMD_CTRL_FUSING_CONTROL_PTN:
case CMD_CTRL_FUSING_PREDISP_PTN:
Call Stack Log
MSVCRTD! 102136a8()
MSVCRTD! 102135b1()
operator delete(void * 0x01a11f28) line 351 + 12 bytes
CString::FreeData() line 146 + 15 bytes
CString::Release() line 157
CString::AllocBeforeWrite(int 1) line 200
CString::AssignCopy(int 1, const char * 0x01e2e684) line 315
CString::operator=(char 48) line 88
CMLT2App::AckTotalFusingMsg(CString {"A2A100BD002300375000011320373000000630331000000C3"}) line 6029
CMLT2App::RS232C_ReceivedFusingInfo(unsigned char * 0x01e2eb8c) line 5412
ThreadWatchComm1(CPortController * 0x01514010) line 966
KERNEL32! 7c7db729()
Related
Description
Sometimes I get exception 3 when trying to clear() a std::vector.
Hardware
Hardware: ESP-07S
ESP8266-Arduino library core version: 2.4.0-rc1
Settings in IDE
Module: Generic ESP8266 Module
Flash Size: 4MB
CPU Frequency: 160Mhz
Flash Mode: qio
Flash Frequency: 40Mhz
Upload Using: OTA / SERIAL
Reset Method: ck
Stacktrace
This is stacktrace from Arduino's Exception Decoder:
Exception 3: LoadStoreError: Processor internal physical address or data error during load or store
Decoding 30 results
0x401000b7: umm_disconnect_from_free_list at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1151
0x4021e9bc: memmove at /Users/igrokhotkov/e/newlib-xtensa/xtensa-lx106-elf/newlib/libc/string/../../../.././newlib/libc/string/memmove.c line 69 (discriminator 1)
0x40217464: Print::write(unsigned char const*, unsigned int) at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/Print.cpp line 38
0x4010020c: _umm_free at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1287
0x4010068c: free at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1733
0x40215b04: operator delete(void*) at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/abi.cpp line 57
0x40207940: std::_Vector_base >::_M_deallocate(double*, unsigned int) at C:\Users\Defozo\Documents\Arduino\jeszcze nowsza wersja laser_na_stacje_v2\laser_na_stacje_v2/laser_na_stacje_v2.ino line 565
0x402088ac: std::_Vector_base >::~_Vector_base() at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_vector.h line 161
0x40209748: std::vector >::_M_erase_at_end(double*) at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_vector.h line 1353
: (inlined by) std::vector >::clear() at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_vector.h line 1126
: (inlined by) loop at C:\Users\Defozo\Documents\Arduino\jeszcze nowsza wersja laser_na_stacje_v2\laser_na_stacje_v2/laser_na_stacje_v2.ino line 412
0x40217082: std::default_delete ::operator()(TransportTraits*) const at c:\users\defozo\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/unique_ptr.h line 68
0x4010020c: _umm_free at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\umm_malloc/umm_malloc.c line 1287
0x401020ea: wDev_ProcessFiq at ?? line ?
0x40215d84: loop_wrapper at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/core_esp8266_main.cpp line 124
0x4010070c: cont_norm at C:\Users\Defozo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266/cont.S line 109
This is reset cause:
Hardware Watchdog
Fatal exception:4 flag:1 (WDT) epc1:0x40000f83 epc2:0x00000000 epc3:0x4000dd3b excvaddr:0x40023c5c depc:0x00000000
Code
I'm initializing vectors like that:
std::vector<double> dhtTempVector, dhtHumidityVector;
std::vector<double> dhtTempMedianVector, dhtHumidityMedianVector;
std::vector<double> bmpTempVector, bmpPressureVector;
std::vector<double> bmpTempMedianVector, bmpPressureMedianVector;
dhtTempVector.reserve(5);
dhtHumidityVector.reserve(5);
bmpTempVector.reserve(5);
bmpPressureVector.reserve(5);
dhtTempMedianVector.reserve(6);
dhtHumidityMedianVector.reserve(6);
bmpPressureMedianVector.reserve(6);
bmpTempMedianVector.reserve(6);
Inserting new values like that:
if (!isnan(temp) && !isnan(hum)) {
dhtTempVector.push_back(temp);
dhtHumidityVector.push_back(hum);
}
and:
if (!dhtTempVector.empty()) {
dhtTempMedianVector.push_back(median(dhtTempVector));
dhtTempVector.clear();
}
if (!dhtHumidityVector.empty()) {
dhtHumidityMedianVector.push_back(median(dhtHumidityVector));
dhtHumidityVector.clear(); //line number 412
}
This is the median function:
double median(std::vector<double> v)
{
size_t n = v.size() / 2;
std::nth_element(v.begin(), v.begin()+n, v.end());
double vn = v[n];
if(v.size()%2 == 1) {
return vn;
} else {
std::nth_element(v.begin(), v.begin()+n-1, v.end());
return 0.5*(vn+v[n-1]);
}
}
Additional debug information
This is a result:
dhtTempVector size: 4
dhtTempMedianVector size: 5
dhtHumidityVector size: 4
dhtHumidityMedianVector size: 5
29.00 29.00 29.00 29.00 --
28.70 28.75 28.80 28.90 28.90 --
41.20 41.30 41.80 41.40 --
42.65 42.55 41.80 42.30 41.75 --
of these lines of code:
Serial.print("dhtTempVector size: ");
Serial.println(dhtTempVector.size());
Serial.print("dhtTempMedianVector size: ");
Serial.println(dhtTempMedianVector.size());
Serial.print("dhtHumidityVector size: ");
Serial.println(dhtHumidityVector.size());
Serial.print("dhtHumidityMedianVector size: ");
Serial.println(dhtHumidityMedianVector.size());
for (int k = 0; k < dhtTempVector.size(); ++k) {
Serial.print(dhtTempVector.at(k));
Serial.print(" ");
}
Serial.println("--");
for (int k = 0; k < dhtTempMedianVector.size(); ++k) {
Serial.print(dhtTempMedianVector.at(k));
Serial.print(" ");
}
Serial.println("--");
for (int k = 0; k < dhtHumidityVector.size(); ++k) {
Serial.print(dhtHumidityVector.at(k));
Serial.print(" ");
}
Serial.println("--");
for (int k = 0; k < dhtHumidityMedianVector.size(); ++k) {
Serial.print(dhtHumidityMedianVector.at(k));
Serial.print(" ");
}
Serial.println("--");
just before the exception is thrown.
Summary
It looks like the exception is thrown during clearing the vector. I think I experienced exceptions thrown at the end of the loop() function too - so at the time when destructors of the vectors are fired. I'd think it's a problem with destroying the elements of the vectors but they're just double numbers.
What could be the problem?
#Edit
The Arduino-ESP8266 library that I'm using is available here:
https://github.com/esp8266
Here is umm_malloc.c:
https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c
Print.cpp:
https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/Print.cpp
cont.S:
https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/cont.S
Specific lines from umm_malloc.c:
1151:
UMM_NFREE(UMM_PFREE(c)) = UMM_NFREE(c);
https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c#L1151
1287:
if( UMM_NBLOCK(UMM_PBLOCK(c)) & UMM_FREELIST_MASK ) {
https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c#L1287
1733:
void umm_free( void *ptr ) {
ptr = GET_UNPOISONED(ptr);
/* check poison of each blocks, if poisoning is enabled */
if (!CHECK_POISON_ALL_BLOCKS()) {
return;
}
/* check full integrity of the heap, if this check is enabled */
if (!INTEGRITY_CHECK()) {
return;
}
_umm_free( ptr );
} //1733
https://github.com/esp8266/Arduino/blob/master/cores/esp8266/umm_malloc/umm_malloc.c#L1733
Specific line from Print.cpp:
size_t Print::write(const uint8_t *buffer, size_t size) {
size_t n = 0;
while(size--) {
n += write(*buffer++); //line number 38
}
return n;
}
https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/Print.cpp#L38
Specific line from core_esp8266_main.cpp:
static void loop_wrapper() {
static bool setup_done = false;
preloop_update_frequency();
if(!setup_done) {
setup();
#ifdef DEBUG_ESP_PORT
DEBUG_ESP_PORT.setDebugOutput(true);
#endif
setup_done = true;
}
loop();
run_scheduled_functions(); //line number 124
esp_schedule();
}
Line number 109 from cont.S:
https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/cores/esp8266/cont.S#L109
I have taken code from here Webduino Network Setp
I added one more field.
struct config_t
{
....
...
.....
byte subnet[4];
byte dns_server[4];
unsigned int webserverPort;
char HostName[10]; // Added code Here..
} eeprom_config;
Snippet..
#define NAMELEN 5
#define VALUELEN 10
void setupNetHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
URLPARAM_RESULT rc;
char name[NAMELEN];
char value[VALUELEN];
boolean params_present = false;
byte param_number = 0;
char buffer [13];
.....
.....
}
Added Lines to read date from web page and Wire to eeprom
Write to eeprom: ( Facing issue here, I need to copy value to eeprom_config.HostName[0] ... )
// read Host Name
if (param_number >= 25 && param_number <= 35) {
// eeprom_config.HostName[param_number - 25] = strtol(value, NULL, 10);
eeprom_config.HostName[param_number - 25] = value ; // Facing Issue here..
}
and...
for (int a = 0; a < 10; a++) {
server.printP(Form_input_text_start);
server.print(a + 25);
server.printP(Form_input_value);
server.print(eeprom_config.HostName[a]);
server.printP(Form_input_size1);
server.printP(Form_input_end);
}
Issue was resolved.
Thanks , got idea from this post.
invalid conversion from char' tochar*'
How ! changed
// read Host Name
if (param_number >= 25 && param_number <= 35) {
// eeprom_config.HostName[param_number - 25] = strtol(value, NULL, 10);
eeprom_config.HostName[param_number - 25] = value ; // Facing Issue here..
}
changed to
// read Host Name
if (param_number >= 25 && param_number <= 35) {
eeprom_config.HostName[param_number - 25] = value[0];
}
Update: To get around the problem below, I have done
if (ftell(m_pFile) != m_strLine.size())
fseek(m_pFile, m_strLine.size(), SEEK_SET);
fpos_t position;
fgetpos(m_pFile, &position);
this then returns the correct position for my file. However, I would still like to understand why this is occurring?
I want to get the position in a text file. For most files I have been reading the first line, storing the position, doing some other stuff and returning to the position afterwards...
m_pFile = Utils::OpenFile(m_strBaseDir + "\\" + Source + "\\" + m_strFile, "r");
m_strLine = Utils::ReadLine(m_pFile);
bEOF = feof(m_pFile) != 0;
if (bEOF)
{
Utils::CompilerError(m_ErrorCallback,
(boost::format("File '%1%' is empty.") % m_strFile).str());
return false;
}
// Open.
pFileCode = Utils::OpenFile(strGenCode + "\\" + m_strFile, options.c_str());
m_strLine = Utils::Trim(m_strLine);
Utils::WriteLine(pFileCode, m_strLine);
// Store location and start passes.
unsigned int nLineCount = 1;
fpos_t position;
fgetpos(m_pFile, &position);
m_strLine = Utils::ReadLine(m_pFile);
...
fsetpos(m_pFile, &position);
m_strLine = Utils::ReadLine(m_pFile);
With all files provided to me the storage of the fgetpos and fsetpos works correctly. The problem is with a file that I have created which looks like
which is almost identical to the supplied files. The problem is that for the file above fgetpos(m_pFile, &position); is not returning the correct position (I am aware that the fpos_t position is implementation specific). After the first ReadLine I get a position of 58 (edited from 60) so that when I attempt to read the second line with
fsetpos(m_pFile, &position);
m_strLine = Utils::ReadLine(m_pFile);
I get
on 700
instead of
Selection: Function ADJEXCL
Why is fgetpos not returning the position of the end of the first line?
_Note. The Utils.ReadLine method is:
std::string Utils::ReadLine(FILE* file)
{
if (file == NULL)
return NULL;
char buffer[MAX_READLINE];
if (fgets(buffer, MAX_READLINE, file) != NULL)
{
if (buffer != NULL)
{
std::string str(buffer);
Utils::TrimNewLineChar(str);
return str;
}
}
std::string str(buffer);
str.clear();
return str;
}
with
void Utils::TrimNewLineChar(std::string& s)
{
if (!s.empty() && s[s.length() - 1] == '\n')
s.erase(s.length() - 1);
}
Edit. Following the debugging suggestions in the comments I have added the following code
m_pFile = Utils::OpenFile(m_strBaseDir + "\\" + Source + "\\" + m_strFile, "r");
m_strLine = Utils::ReadLine(m_pFile);
// Here m-strLine = " Logic Definition Report Chart Version: New Version 700" (64 chars).
long vv = ftell(m_pFile); // Here vv = 58!?
fpos_t pos;
vv = ftell(m_pFile);
fgetpos(m_pFile, &pos); // pos = 58.
fsetpos(m_pFile, &pos);
m_strLine = Utils::ReadLine(m_pFile);
Sorry, but your Utils functions have clearly been written by an incompetent. Some issues are just a matter of style. For trimming:
void Utils::TrimNewLineChar(std::string& s)
{
if (!s.empty() && *s.rbegin() == '\n')
s.resize(s.size() - 1); // resize, not erase
}
or in C++11
void Utils::TrimNewLineChar(std::string& s)
{
if (!s.empty() && s.back() == '\n')
s.pop_back();
}
ReadLine is even worse, replace it with:
std::string Utils::ReadLine(FILE* file)
{
std::string str;
char buffer[MAX_READLINE];
if (file != NULL && fgets(buffer, MAX_READLINE, file) != NULL)
{
// it is guaranteed that buffer != NULL, since it is an automatic array
str.assign(buffer);
Utils::TrimNewLineChar(str);
}
// copying buffer into str is useless here
return str;
}
That last str(buffer) in the original worries me especially. If fgets reaches a newline, fills the buffer, or reaches end of file, you're guaranteed to get a properly terminated string in your buffer. If some other I/O error occurs? Who knows? It might be undefined behavior.
Best not to rely on the value of buffer when fgets fails.
I do debug this code:
result = conn_process(conn, 1, 0);
if (result == CG_ERR_OK) continue;
if (result == CG_ERR_TIMEOUT)
{
break; // i'm here!
}
As in debugger i'm at break; I assume that result == CG_ERR_TIMEOUT is true. In Locals I do see:
result 131075 unsigned int
In Watch I do see:
CG_ERR_TIMEOUT error: identifier 'CG_ERR_TIMEOUT' out of scope
Going to definition shows me such code:
enum {
CG_ERR_OK = 0,
CG_ERR_INTERNAL = CG_RANGE_BEGIN,
CG_ERR_INVALIDARGUMENT,
CG_ERR_UNSUPPORTED,
CG_ERR_TIMEOUT,
CG_ERR_MORE,
CG_ERR_INCORRECTSTATE,
CG_ERR_DUPLICATEID,
CG_ERR_BUFFERTOOSMALL,
CG_ERR_OVERFLOW,
CG_ERR_UNDERFLOW,
CG_RANGE_END
};
So I just wonder why CG_ERR_TIMEOUT == 131075. What a strange magic number?
Because CG_RANGE_BEGIN is 131072 (which is 0x20000).
enum {
CG_ERR_OK = 0,
CG_ERR_INTERNAL = CG_RANGE_BEGIN, // == 131072
From now on every enum value is the previous one plus 1:
CG_ERR_INVALIDARGUMENT, // == 131072 + 1 = 131073
CG_ERR_UNSUPPORTED, // == 131073 + 1 = 131074
CG_ERR_TIMEOUT, // == 131074 + 1 = 131075
CG_ERR_MORE, // etc.
CG_ERR_INCORRECTSTATE,
CG_ERR_DUPLICATEID,
CG_ERR_BUFFERTOOSMALL,
CG_ERR_OVERFLOW,
CG_ERR_UNDERFLOW,
CG_RANGE_END
};
i am working on a program to authenticate an ENC signature file by using OpenSSL for windows, and specifically methods DSA_do_verify(...) and SHA1(...) hash algorithm, but is having problems as the result from DSA_do_verify is always 0 (invalid).
I am using the signature file of test set 4B from the IHO S-63 Data Protection Scheme, and also the SA public key (downloadable from IHO) for verification.
Below is my program, can anyone help to see where i have gone wrong as i have tried many ways but failed to get the verification to be valid, thanks..
The signature file from test set 4B
// Signature part R:
3F14 52CD AEC5 05B6 241A 02C7 614A D149 E7D6 C408.
// Signature part S:
44BB A3DB 8C46 8D11 B6DB 23BE 1A79 55E6 B083 7429.
// Signature part R:
93F5 EF86 1FF6 BA6F 1C2B B9BB 7F36 0C80 2F9B 2414.
// Signature part S:
4877 8130 12B4 50D8 3688 B52C 7A84 8E26 D442 8B6E.
// BIG p
C16C BAD3 4D47 5EC5 3966 95D6 94BC 8BC4 7E59 8E23 B5A9 D7C5 CEC8 2D65 B682 7D44 E953 7848 4730 C0BF F1F4 CB56 F47C 6E51 054B E892 00F3 0D43 DC4F EF96 24D4 665B.
// BIG q
B7B8 10B5 8C09 34F6 4287 8F36 0B96 D7CC 26B5 3E4D.
// BIG g
4C53 C726 BDBF BBA6 549D 7E73 1939 C6C9 3A86 9A27 C5DB 17BA 3CAC 589D 7B3E 003F A735 F290 CFD0 7A3E F10F 3515 5F1A 2EF7 0335 AF7B 6A52 11A1 1035 18FB A44E 9718.
// BIG y
15F8 A502 11C2 34BB DF19 B3CD 25D1 4413 F03D CF38 6FFC 7357 BCEE 59E4 EBFD B641 6726 5E5F 0682 47D4 B50B 3B86 7A85 FB4D 6E01 8329 A993 C36C FD9A BFB6 ED6D 29E0.
dataServer_pkeyfile.txt (extracted from above)
// BIG p
C16C BAD3 4D47 5EC5 3966 95D6 94BC 8BC4 7E59 8E23 B5A9 D7C5 CEC8 2D65 B682 7D44 E953 7848 4730 C0BF F1F4 CB56 F47C 6E51 054B E892 00F3 0D43 DC4F EF96 24D4 665B.
// BIG q
B7B8 10B5 8C09 34F6 4287 8F36 0B96 D7CC 26B5 3E4D.
// BIG g
4C53 C726 BDBF BBA6 549D 7E73 1939 C6C9 3A86 9A27 C5DB 17BA 3CAC 589D 7B3E 003F A735 F290 CFD0 7A3E F10F 3515 5F1A 2EF7 0335 AF7B 6A52 11A1 1035 18FB A44E 9718.
// BIG y
15F8 A502 11C2 34BB DF19 B3CD 25D1 4413 F03D CF38 6FFC 7357 BCEE 59E4 EBFD B641 6726 5E5F 0682 47D4 B50B 3B86 7A85 FB4D 6E01 8329 A993 C36C FD9A BFB6 ED6D 29E0.
Program abstract:
QbyteArray pk_data;
QFile pk_file("./dataServer_pkeyfile.txt");
if (pk_file.open(QIODevice::Text | QIODevice::ReadOnly))
{
pk_data.append(pk_file.readAll());
}
pk_file.close();
unsigned char ptr_sha_hashed[20];
unsigned char *ptr_pk_data = (unsigned char *)pk_data.data();
// openssl SHA1 hashing algorithm
SHA1(ptr_pk_data, pk_data.length(), ptr_sha_hashed);
DSA_SIG *dsasig = DSA_SIG_new();
char ptr_r[] = "93F5EF861FF6BA6F1C2BB9BB7F360C802F9B2414"; //from tset 4B
char ptr_s[] = "4877813012B450D83688B52C7A848E26D4428B6E"; //from tset 4B
if (BN_hex2bn(&dsasig->r, ptr_r) == 0) return 0;
if (BN_hex2bn(&dsasig->s, ptr_s) == 0) return 0;
DSA *dsakeys = DSA_new();
//the following values are from the SA public key
char ptr_p[] = "FCA682CE8E12CABA26EFCCF7110E526DB078B05EDECBCD1EB4A208F3AE1617AE01F35B91A47E6DF63413C5E12ED0899BCD132ACD50D99151BDC43EE737592E17";
char ptr_q[] = "962EDDCC369CBA8EBB260EE6B6A126D9346E38C5";
char ptr_g[] = "678471B27A9CF44EE91A49C5147DB1A9AAF244F05A434D6486931D2D14271B9E35030B71FD73DA179069B32E2935630E1C2062354D0DA20A6C416E50BE794CA4";
char ptr_y[] = "963F14E32BA5372928F24F15B0730C49D31B28E5C7641002564DB95995B15CF8800ED54E354867B82BB9597B158269E079F0C4F4926B17761CC89EB77C9B7EF8";
if (BN_hex2bn(&dsakeys->p, ptr_p) == 0) return 0;
if (BN_hex2bn(&dsakeys->q, ptr_q) == 0) return 0;
if (BN_hex2bn(&dsakeys->g, ptr_g) == 0) return 0;
if (BN_hex2bn(&dsakeys->pub_key, ptr_y) == 0) return 0;
int result; //valid = 1, invalid = 0, error = -1
result = DSA_do_verify(ptr_sha_hashed, 20, dsasig, dsakeys);
//result is 0 (invalid)
Found the problem.. should open the file as binary, instead of text as follows:
if (pk_file.open(QIODevice::ReadOnly))