usrz / javascript-barcodes

A small library to generate PDF417 and QR-codes in JavaScript
GNU Lesser General Public License v3.0
5 stars 1 forks source link

Undefined property warning in console #1

Open rcliftonharvey opened 6 years ago

rcliftonharvey commented 6 years ago

https://github.com/usrz/javascript-barcodes/blob/d1540e9b5b687610a0692f6b6d428537457b7aa1/bcmath/libbcmath.js#L154

Line 154 currently leads to the while loop checking for an out-of-range ptr in str, so there's always an "undefined property" warning in the browser console. Can be fixed by using a for loop instead, of course the ptr then doesn't have to be incremented inside the loop anymore:

for(;ptr < str.length;++ptr)
{ //bcmath.isdigit(str[ptr])) {
  //ptr++;
  strscale++;    /* digits */
}
rcliftonharvey commented 6 years ago

Actually, the entire section between line 144 and 157 is prone to out-of-range ptr indices, especially when calculating non floating point values, e.g. 10 10 instead of 10.0 10.0 ... just replace line 144 to 157 with the following snippet:

//while (bcmath.isdigit(str[ptr]))
while((ptr<str.length) && ((str[ptr]) % 1 === 0))
{ //bcmath.isdigit(str[ptr])) {
    ptr++;
    digits++;    /* digits */
 }

if((ptr<str.length) && (str[ptr] === '.'))
{
    ptr++;            /* decimal point */
}

//while (bcmath.isdigit(str[ptr])) {
//while((str[ptr]) % 1 === 0)
for(;ptr < str.length;++ptr)
{ //bcmath.isdigit(str[ptr])) {
    //ptr++;
    strscale++;    /* digits */
}