File tree 1 file changed +10
-7
lines changed
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -385,14 +385,17 @@ void QRCode::handler(std::string &result) {
385
385
quirc_end (this ->qrData );
386
386
387
387
if (quirc_count (this ->qrData ) > 0 ) {
388
- struct quirc_code code;
389
- struct quirc_data scan_data;
390
- quirc_extract (this ->qrData , 0 , &code);
391
-
392
- if (!quirc_decode (&code, &scan_data)) {
388
+ // `quirc_decode` uses some large stack buffers, which is why
389
+ // `code` and `scan_data` here are allocated on the heap to leave
390
+ // just barely enough stack space for it to not overflow the stack.
391
+ std::unique_ptr<struct quirc_code > code = std::make_unique<struct quirc_code >();
392
+ std::unique_ptr<struct quirc_data > scan_data = std::make_unique<struct quirc_data >();
393
+ quirc_extract (this ->qrData , 0 , code.get ());
394
+
395
+ if (!quirc_decode (code.get (), scan_data.get ())) {
393
396
this ->finish ();
394
- this ->out .resize (scan_data. payload_len );
395
- std::copy (scan_data. payload , scan_data. payload + scan_data. payload_len , this ->out .begin ());
397
+ this ->out .resize (scan_data-> payload_len );
398
+ std::copy (scan_data-> payload , scan_data-> payload + scan_data-> payload_len , this ->out .begin ());
396
399
397
400
/* From scanned stuff. */
398
401
if (this ->out .empty ()) result = " " ;
You can’t perform that action at this time.
0 commit comments