Changeset a7b1071 in mainline


Ignore:
Timestamp:
2009-04-03T19:48:10Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a2c479
Parents:
c8bf88d
Message:

Fix bugs in kconsole, simplify string comparisons.

Location:
kernel/generic/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/kconsole.c

    rc8bf88d ra7b1071  
    510510                prev = offset;
    511511        }
    512         *end = offset;
     512        *end = prev;
    513513       
    514514        return found_start;
  • kernel/generic/src/lib/string.c

    rc8bf88d ra7b1071  
    459459int str_cmp(const char *s1, const char *s2)
    460460{
    461         wchar_t c1;
    462         wchar_t c2;
     461        wchar_t c1 = 0;
     462        wchar_t c2 = 0;
    463463       
    464464        size_t off1 = 0;
    465465        size_t off2 = 0;
    466        
    467         while ((c1 = str_decode(s1, &off1, STR_NO_LIMIT) != 0)
    468             && (c2 = str_decode(s2, &off2, STR_NO_LIMIT) != 0)) {
    469                
    470                 if (off1 != off2)
    471                         break;
    472                
     466
     467        while (true) {
     468                c1 = str_decode(s1, &off1, STR_NO_LIMIT);
     469                c2 = str_decode(s2, &off2, STR_NO_LIMIT);
     470
    473471                if (c1 < c2)
    474472                        return -1;
     
    476474                if (c1 > c2)
    477475                        return 1;
    478         }
    479        
    480         if ((off1 == off2) && (c1 == c2))
    481                 return 0;
    482        
    483         if ((c1 == 0) || (off1 < off2))
    484                 return -1;
    485        
    486         return 1;
     476
     477                if (c1 == 0 || c2 == 0)
     478                        break;         
     479        }
     480
     481        return 0;
    487482}
    488483
     
    510505       
    511506        count_t len = 0;
    512        
    513         while ((len < max_len)
    514             && ((c1 = str_decode(s1, &off1, STR_NO_LIMIT)) != 0)
    515             && ((c2 = str_decode(s2, &off2, STR_NO_LIMIT)) != 0)) {
    516                
    517                 if (off1 != off2)
     507
     508        while (true) {
     509                if (len >= max_len)
    518510                        break;
    519                
     511
     512                c1 = str_decode(s1, &off1, STR_NO_LIMIT);
     513                c2 = str_decode(s2, &off2, STR_NO_LIMIT);
     514
    520515                if (c1 < c2)
    521516                        return -1;
    522                
     517
    523518                if (c1 > c2)
    524519                        return 1;
    525                
    526                 len++;
    527         }
    528        
    529         if ((off1 == off2) && (len == max_len) && (c1 == c2))
    530                 return 0;
    531        
    532         if ((c1 == 0) || (off1 < off2))
    533                 return -1;
    534        
    535         return 1;
     520
     521                if (c1 == 0 || c2 == 0)
     522                        break;
     523
     524                ++len; 
     525        }
     526
     527        return 0;
     528
    536529}
    537530
     
    559552        size_t dst_off = 0;
    560553       
    561         while ((ch = str_decode(src, &str_off, STR_NO_LIMIT) != 0)) {
     554        while ((ch = str_decode(src, &str_off, STR_NO_LIMIT)) != 0) {
    562555                if (chr_encode(ch, dst, &dst_off, size) != EOK)
    563556                        break;
     
    617610        size_t off = 0;
    618611       
    619         while ((acc = str_decode(str, &off, STR_NO_LIMIT) != 0)) {
     612        while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
    620613                if (acc == ch)
    621614                        return (str + off);
Note: See TracChangeset for help on using the changeset viewer.