From 82592941fbb012a0581e63f3c22ceb5ae38a1026 Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Sat, 23 Mar 2013 16:12:34 +0000 Subject: Better support for error in Chrome --- src/examples/rrdContent.html | 4 ++++ src/examples/rrdHeaderInfo.html | 4 ++++ src/examples/rrdJFlot.html | 5 +++++ src/examples/rrdJFlotDefaults.html | 4 ++++ src/examples/rrdJFlotFilter.html | 4 ++++ src/examples/rrdJFlotFilterRRA.html | 4 ++++ src/examples/rrdJFlotSimple.html | 4 ++++ src/examples/rrdJFlotTwo.html | 8 ++++++++ src/examples/rrdMatrixFlot.html | 4 ++++ src/lib/rrdFile.js | 2 ++ 10 files changed, 43 insertions(+) diff --git a/src/examples/rrdContent.html b/src/examples/rrdContent.html index 9b87412..21d7082 100644 --- a/src/examples/rrdContent.html +++ b/src/examples/rrdContent.html @@ -161,6 +161,10 @@ // and performs the update of the Web page function update_fname_handler(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/examples/rrdHeaderInfo.html b/src/examples/rrdHeaderInfo.html index 3a772d7..c0feddb 100644 --- a/src/examples/rrdHeaderInfo.html +++ b/src/examples/rrdHeaderInfo.html @@ -102,6 +102,10 @@ // and performs the update of the Web page function update_info_handler(bf) { var rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname+" is empty (possibly loading failed)!"); + return 1; + } try { var rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/examples/rrdJFlot.html b/src/examples/rrdJFlot.html index 9c24f59..b5fb4a5 100644 --- a/src/examples/rrdJFlot.html +++ b/src/examples/rrdJFlot.html @@ -87,10 +87,15 @@ // and performs the update of the Web page function update_fname_handler(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { alert("File "+fname+" is not a valid RRD archive!\n"+err); + return 1; } if (i_rrd_data!=undefined) { rrd_data=i_rrd_data; diff --git a/src/examples/rrdJFlotDefaults.html b/src/examples/rrdJFlotDefaults.html index d25961e..35f1ee0 100644 --- a/src/examples/rrdJFlotDefaults.html +++ b/src/examples/rrdJFlotDefaults.html @@ -95,6 +95,10 @@ // and performs the update of the Web page function update_fname_handler(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/examples/rrdJFlotFilter.html b/src/examples/rrdJFlotFilter.html index c588e90..1fee276 100644 --- a/src/examples/rrdJFlotFilter.html +++ b/src/examples/rrdJFlotFilter.html @@ -127,6 +127,10 @@ // and performs the update of the Web page function update_fname_handler(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/examples/rrdJFlotFilterRRA.html b/src/examples/rrdJFlotFilterRRA.html index 7306e37..8f001d4 100644 --- a/src/examples/rrdJFlotFilterRRA.html +++ b/src/examples/rrdJFlotFilterRRA.html @@ -121,6 +121,10 @@ // and performs the update of the Web page function update_fname_handler(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/examples/rrdJFlotSimple.html b/src/examples/rrdJFlotSimple.html index 4240f70..81645c4 100644 --- a/src/examples/rrdJFlotSimple.html +++ b/src/examples/rrdJFlotSimple.html @@ -108,6 +108,10 @@ // and performs the update of the Web page function update_fname_handler(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/examples/rrdJFlotTwo.html b/src/examples/rrdJFlotTwo.html index 2aed031..4d1c79c 100644 --- a/src/examples/rrdJFlotTwo.html +++ b/src/examples/rrdJFlotTwo.html @@ -95,6 +95,10 @@ // and performs the update of the Web page function update_fname_handler1(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname1+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { @@ -108,6 +112,10 @@ function update_fname_handler2(bf) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File "+fname2+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/examples/rrdMatrixFlot.html b/src/examples/rrdMatrixFlot.html index 0f61b07..66b3b17 100644 --- a/src/examples/rrdMatrixFlot.html +++ b/src/examples/rrdMatrixFlot.html @@ -81,6 +81,10 @@ // and performs the update of the Web page function update_fname_handler(bf,idx) { var i_rrd_data=undefined; + if (bf.getLength()<1) { + alert("File at idx "+idx+" is empty (possibly loading failed)!"); + return 1; + } try { var i_rrd_data=new RRDFile(bf); } catch(err) { diff --git a/src/lib/rrdFile.js b/src/lib/rrdFile.js index 0f7c80d..81f7731 100644 --- a/src/lib/rrdFile.js +++ b/src/lib/rrdFile.js @@ -204,6 +204,8 @@ function RRDHeader(rrd_data) { // Internal, used for initialization RRDHeader.prototype.validate_rrd = function() { + if (this.rrd_data.getLength()<1) throw new InvalidRRD("Empty file."); + if (this.rrd_data.getLength()<16) throw new InvalidRRD("File too short."); if (this.rrd_data.getCStringAt(0,4)!=="RRD") throw new InvalidRRD("Wrong magic id."); this.rrd_version=this.rrd_data.getCStringAt(4,5); -- cgit v1.1-4-g5e80