Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/12/09 14:14
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#165268 - Alternative parsing
Responding to: ???'s previous message
Do you mean null as in backslash-zero? This is the same as just writing "if (SBUF != 0)".

But once more: An X followed by a couple of hundred characters that are not X and not zero, will result in a very nice buffer overflow, since your state machine does not keep track of how many characters you have seen.

Why not just do:
ch = SBUF;
switch (state) {
    case WAIT_START:
        switch (ch) {
            case 'P': state = GET_P: idx = 0; break;
            case 'D': state = GET_D; idx = 0; break;
            ...
            default:
                ; // continue waiting for a valid command character
        }
        break;
    case WAIT_P:
        if (ch == '.' || ch >= '0' && ch <= '9') {
            if (idx < BUF_SIZE-1) {
                buf[idx++] = ch;
            } else {
                // error somewhere - too much data.
                state = WAIT_START;
            }
        } else {
            // first character not part of number.
            buf[idx] = '';
            my_num = atof(buf);
            store_proportional(my_num);
            // wait for new start character
            state = WAIT_START;
        }
        break;
    ...
    default:
        // error - unknown state.
        state = WAIT_START;
}

 


List of 29 messages in thread
TopicAuthorDate
Command Processor            01/01/70 00:00      
   More detail required            01/01/70 00:00      
      Command Processor            01/01/70 00:00      
         Standard Async Serial (updated)            01/01/70 00:00      
         What is it that you need?            01/01/70 00:00      
            Command Processor            01/01/70 00:00      
               What compiler?            01/01/70 00:00      
                  Code to Get command            01/01/70 00:00      
                     Buffer overflow...            01/01/70 00:00      
                        Sorry            01/01/70 00:00      
                     did you retype the code?? ....            01/01/70 00:00      
                        This code is translated            01/01/70 00:00      
                           Alternative parsing            01/01/70 00:00      
                              Code to Get command            01/01/70 00:00      
                           wasteful            01/01/70 00:00      
               I would not do this in 'C'            01/01/70 00:00      
                  Thank you            01/01/70 00:00      
                     Assembler floating point?            01/01/70 00:00      
                        I didn't say he shouldn't use 'C' at all ...            01/01/70 00:00      
                  'C' may not be that bad            01/01/70 00:00      
                     Just this particular function would be very fast in ASM            01/01/70 00:00      
                        Maybe; maybe not...            01/01/70 00:00      
                           The opinion that assembler is faster than C            01/01/70 00:00      
                              In this case, speed isn't a big factor.            01/01/70 00:00      
                                 dead easy and it will not work if you do not            01/01/70 00:00      
                                    no (keil?) C will work if the main is in asm            01/01/70 00:00      
                                       What I was considering            01/01/70 00:00      
                  I WOULD write thsi in C            01/01/70 00:00      
                     Thta doesn't surprise me.            01/01/70 00:00      

Back to Subject List