Skip to content

Commit

Permalink
Fix crash caused by vector
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Nov 6, 2024
1 parent ff8cefa commit c2843ad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
15 changes: 6 additions & 9 deletions examples/command-line/base64decoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ var fs = require('fs');
// Get a license key from https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform
dbr.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");

fs.readFile('base64.txt', 'utf8', (err, data) => {
fs.readFile('base64.txt', 'utf8', async (err, data) => {
for (let i = 0; i < 5; i++) {
msg = await dbr.decodeBase64Async(data, barcodeTypes, "");
console.log(msg);
console.log('.................');
}

dbr.decodeBase64Async(data, barcodeTypes, function (err, msg) {
for (let index in msg) {
var result = msg[index]
console.log(result['format']);
console.log(result['value']);
console.log("##################");
}
}, "");
});
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "barcode4nodejs",
"version": "10.0.2",
"version": "10.0.3",
"description": "Node.js bindings to Dynamsoft Barcode Reader C/C++ SDK.",
"keywords": [
"barcode",
Expand Down Expand Up @@ -56,8 +56,5 @@
"devDependencies": {
"@types/node": "^20.14.2",
"node-gyp": "^10.1.0"
},
"dependencies": {
"barcode4nodejs": "file:"
}
}
}
10 changes: 5 additions & 5 deletions src/dbr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ void BarcodeReader::ProcessImage(BarcodeWorker *worker)
int endtime = gettime();
int elapsedTime = endtime - starttime;

worker->pResults = worker->capturedReceiver->results;
worker->pResults = &worker->capturedReceiver->results;
worker->errorCode = ret;
worker->elapsedTime = elapsedTime;
}

void BarcodeReader::WrapResults(BarcodeWorker *worker, Napi::Env env, Napi::Object &result)
{
vector<CDecodedBarcodesResult *> pResults = worker->pResults;
vector<CDecodedBarcodesResult *> *pResults = worker->pResults;
Napi::Array barcodeResults = Napi::Array::New(env);
for (int j = 0; j < pResults.size(); j++)
for (int j = 0; j < pResults->size(); j++)
{
CDecodedBarcodesResult *barcodeResult = pResults[j];
CDecodedBarcodesResult *barcodeResult = (*pResults)[j];

if (barcodeResult)
{
Expand Down Expand Up @@ -247,7 +247,7 @@ void BarcodeReader::WrapResults(BarcodeWorker *worker, Napi::Env env, Napi::Obje
}

result = barcodeResults;
worker->pResults.clear();
worker->pResults->clear();
}

/*
Expand Down
10 changes: 5 additions & 5 deletions src/dbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ typedef enum

struct BarcodeWorker
{
uv_work_t request; // libuv
Napi::FunctionReference callback; // javascript callback
int iFormat; // barcode types
std::string filename; // file name
vector<CDecodedBarcodesResult *> pResults; // result pointer
uv_work_t request; // libuv
Napi::FunctionReference callback; // javascript callback
int iFormat; // barcode types
std::string filename; // file name
vector<CDecodedBarcodesResult *> *pResults; // result pointer
unsigned char *buffer;
int size; // file size
int errorCode; // detection error code
Expand Down

0 comments on commit c2843ad

Please sign in to comment.