Changeset 14961 for trunk/FACT++


Ignore:
Timestamp:
02/25/13 15:48:18 (12 years ago)
Author:
tbretz
Message:
Make sure that the stoi if failing cannot crash the program.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/magiclidar.cc

    r14950 r14961  
    8585
    8686        bool keepalive = false;
     87        bool failed = false;
    8788
    8889        stringstream is(str);
     
    112113            else
    113114            {
    114                 if (line.substr(0, 3)=="ZEN")
    115                     data.fZd = stoi(line.substr(3));
    116                 if (line.substr(0, 2)=="AZ")
    117                     data.fAz = stof(line.substr(2));
    118 
    119                 if (line.substr(0, 3)=="PBL")
    120                     data.fPBL = stof(line.substr(3));
    121                 if (line.substr(0, 3)=="CHE")
    122                     data.fCHE = stof(line.substr(3));
    123                 if (line.substr(0, 3)=="COT")
    124                     data.fCOT = stof(line.substr(3));
    125 
    126                 if (line.substr(0, 2)=="T3")
    127                     data.fT3 = stof(line.substr(2));
    128                 if (line.substr(0, 2)=="T6")
    129                     data.fT6 = stof(line.substr(2));
    130                 if (line.substr(0, 2)=="T9")
    131                     data.fT9 = stof(line.substr(2));
    132                 if (line.substr(0, 3)=="T12")
    133                     data.fT12 = stof(line.substr(3));
    134 
    135                 if (line.substr(0, 4)=="HOUR")
    136                     hh = stoi(line.substr(4));
    137                 if (line.substr(0, 6)=="MINUTS")
    138                     mm = stoi(line.substr(6));
    139                 if (line.substr(0, 7)=="SECONDS")
    140                     ss = stoi(line.substr(7));
    141 
    142                 if (line.substr(0, 4)=="YEAR")
    143                     y = stoi(line.substr(4));
    144                 if (line.substr(0, 5)=="MONTH")
    145                     m = stoi(line.substr(5));
    146                 if (line.substr(0, 3)=="DAY")
    147                     d = stoi(line.substr(3));
     115                try
     116                {
     117                    if (line.substr(0, 3)=="ZEN")
     118                        data.fZd = stoi(line.substr(3));
     119                    if (line.substr(0, 2)=="AZ")
     120                        data.fAz = stof(line.substr(2));
     121
     122                    if (line.substr(0, 3)=="PBL")
     123                        data.fPBL = stof(line.substr(3));
     124                    if (line.substr(0, 3)=="CHE")
     125                        data.fCHE = stof(line.substr(3));
     126                    if (line.substr(0, 3)=="COT")
     127                        data.fCOT = stof(line.substr(3));
     128
     129                    if (line.substr(0, 2)=="T3")
     130                        data.fT3 = stof(line.substr(2));
     131                    if (line.substr(0, 2)=="T6")
     132                        data.fT6 = stof(line.substr(2));
     133                    if (line.substr(0, 2)=="T9")
     134                        data.fT9 = stof(line.substr(2));
     135                    if (line.substr(0, 3)=="T12")
     136                        data.fT12 = stof(line.substr(3));
     137
     138                    if (line.substr(0, 4)=="HOUR")
     139                        hh = stoi(line.substr(4));
     140                    if (line.substr(0, 6)=="MINUTS")
     141                        mm = stoi(line.substr(6));
     142                    if (line.substr(0, 7)=="SECONDS")
     143                        ss = stoi(line.substr(7));
     144
     145                    if (line.substr(0, 4)=="YEAR")
     146                        y = stoi(line.substr(4));
     147                    if (line.substr(0, 5)=="MONTH")
     148                        m = stoi(line.substr(5));
     149                    if (line.substr(0, 3)=="DAY")
     150                        d = stoi(line.substr(3));
     151                }
     152                catch (const exception &e)
     153                {
     154                    Warn("Conversion of received data failed");
     155                    failed = true;
     156                    break;
     157                }
    148158            }
    149159        }
     
    151161        if (!keepalive)
    152162            PostClose(false);
     163
     164        if (failed)
     165            return;
    153166
    154167        try
Note: See TracChangeset for help on using the changeset viewer.