Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset f737c1d5 in mainline


Ignore:
Timestamp:
2011-08-21T10:53:08Z (10 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master
Children:
b9ae539
Parents:
6045ecf
Message:

Fix bdsh completion crash

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/compl.c

    r6045ecf rf737c1d5  
    9999        tokenizer_t tok;
    100100        token_t tokens[WORD_MAX];
    101         unsigned int current_token;
     101        int current_token;
    102102        size_t tokens_length;
    103103
     
    127127       
    128128        /* Find the current token */
    129         for (current_token = 0; current_token < tokens_length; current_token++) {
     129        for (current_token = 0; current_token < (int) tokens_length;
     130            current_token++) {
    130131                token_t *t = &tokens[current_token];
    131132                size_t end = t->char_start + t->char_length;
     
    137138                }
    138139        }
    139        
    140         if (tokens[current_token].type != TOKTYPE_SPACE) {
     140        if (tokens_length == 0) current_token = -1;
     141       
     142        if (current_token >= 0 && tokens[current_token].type != TOKTYPE_SPACE) {
    141143                *cstart = tokens[current_token].char_start;
    142144        }
     
    154156                goto error;
    155157        }
    156 
    157         str_ncpy(prefix, pref_size + 1, stext +
    158             tokens[current_token].byte_start, pref_size);
     158        prefix[pref_size] = 0;
     159
     160        if (current_token >= 0) {
     161                str_ncpy(prefix, pref_size + 1, stext +
     162                    tokens[current_token].byte_start, pref_size);
     163        }
    159164
    160165        /*
     
    166171        /* Skip any whitespace before current token */
    167172        int prev_token = current_token - 1;
    168         if (prev_token != -1 && tokens[prev_token].type == TOKTYPE_SPACE) {
     173        if (prev_token >= 0 && tokens[prev_token].type == TOKTYPE_SPACE) {
    169174                prev_token--;
    170175        }
     
    174179         * follows a pipe token.
    175180         */
    176         if (prev_token == -1 || tokens[prev_token].type == TOKTYPE_SPACE)
     181        if (prev_token < 0 || tokens[prev_token].type == TOKTYPE_SPACE)
    177182                cs->is_command = true;
    178183        else
Note: See TracChangeset for help on using the changeset viewer.