usrz/javascript-barcodes

Undefined property warning in console

Opened this issue · 1 comments

while ((str[ptr]) % 1 === 0) { //libbcmath.isdigit(str[ptr])) {

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 */
}

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 */
}