diff options
Diffstat (limited to 'gr-trellis')
-rw-r--r-- | gr-trellis/src/lib/fsm.cc | 20 | ||||
-rw-r--r-- | gr-trellis/src/lib/interleaver.cc | 13 |
2 files changed, 28 insertions, 5 deletions
diff --git a/gr-trellis/src/lib/fsm.cc b/gr-trellis/src/lib/fsm.cc index c65b13456..5950b56b9 100644 --- a/gr-trellis/src/lib/fsm.cc +++ b/gr-trellis/src/lib/fsm.cc @@ -86,16 +86,30 @@ fsm::fsm(const char *name) if((fsmfile=fopen(name,"r"))==NULL) throw std::runtime_error ("fsm::fsm(const char *name): file open error\n"); //printf("file open error in fsm()\n"); + + if(fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O) == EOF) { + if(ferror(fsmfile) != 0) + throw std::runtime_error ("fsm::fsm(const char *name): file read error\n"); + } - fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O); d_NS.resize(d_I*d_S); d_OS.resize(d_I*d_S); for(int i=0;i<d_S;i++) { - for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_NS[i*d_I+j])); + for(int j=0;j<d_I;j++) { + if(fscanf(fsmfile,"%d",&(d_NS[i*d_I+j])) == EOF) { + if(ferror(fsmfile) != 0) + throw std::runtime_error ("fsm::fsm(const char *name): file read error\n"); + } + } } for(int i=0;i<d_S;i++) { - for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_OS[i*d_I+j])); + for(int j=0;j<d_I;j++) { + if(fscanf(fsmfile,"%d",&(d_OS[i*d_I+j])) == EOF) { + if(ferror(fsmfile) != 0) + throw std::runtime_error ("fsm::fsm(const char *name): file read error\n"); + } + } } generate_PS_PI(); diff --git a/gr-trellis/src/lib/interleaver.cc b/gr-trellis/src/lib/interleaver.cc index 077416f80..ff15eeadc 100644 --- a/gr-trellis/src/lib/interleaver.cc +++ b/gr-trellis/src/lib/interleaver.cc @@ -75,11 +75,20 @@ interleaver::interleaver(const char *name) throw std::runtime_error ("file open error in interleaver()"); //printf("file open error in interleaver()\n"); - fscanf(interleaverfile,"%d\n",&d_K); + if(fscanf(interleaverfile,"%d\n",&d_K) == EOF) { + if(ferror(interleaverfile) != 0) + throw std::runtime_error ("interleaver::interleaver(const char *name): file read error\n"); + } + d_INTER.resize(d_K); d_DEINTER.resize(d_K); - for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i])); + for(int i=0;i<d_K;i++) { + if(fscanf(interleaverfile,"%d",&(d_INTER[i])) == EOF) { + if(ferror(interleaverfile) != 0) + throw std::runtime_error ("interleaver::interleaver(const char *name): file read error\n"); + } + } // generate DEINTER table for(int i=0;i<d_K;i++) { |