Mercurial > vim
comparison src/regexp.c @ 12752:09c856605191 v8.0.1254
patch 8.0.1254: undefined left shift in gethexchrs()
commit https://github.com/vim/vim/commit/4c22a91d20cce4f28dd2852a13129b5a4cc691da
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 2 22:29:38 2017 +0100
patch 8.0.1254: undefined left shift in gethexchrs()
Problem: Undefined left shift in gethexchrs(). (geeknik)
Solution: Use unsigned long. (idea by Christian Brabandt, closes https://github.com/vim/vim/issues/2255)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 02 Nov 2017 22:30:05 +0100 |
parents | e769c912fcd9 |
children | ac42c4b11dbc |
comparison
equal
deleted
inserted
replaced
12751:9487518a1635 | 12752:09c856605191 |
---|---|
693 static int getchr(void); | 693 static int getchr(void); |
694 static void skipchr_keepstart(void); | 694 static void skipchr_keepstart(void); |
695 static int peekchr(void); | 695 static int peekchr(void); |
696 static void skipchr(void); | 696 static void skipchr(void); |
697 static void ungetchr(void); | 697 static void ungetchr(void); |
698 static int gethexchrs(int maxinputlen); | 698 static long gethexchrs(int maxinputlen); |
699 static int getoctchrs(void); | 699 static long getoctchrs(void); |
700 static int getdecchrs(void); | 700 static long getdecchrs(void); |
701 static int coll_get_char(void); | 701 static int coll_get_char(void); |
702 static void regcomp_start(char_u *expr, int flags); | 702 static void regcomp_start(char_u *expr, int flags); |
703 static char_u *reg(int, int *); | 703 static char_u *reg(int, int *); |
704 static char_u *regbranch(int *flagp); | 704 static char_u *regbranch(int *flagp); |
705 static char_u *regconcat(int *flagp); | 705 static char_u *regconcat(int *flagp); |
1835 break; | 1835 break; |
1836 | 1836 |
1837 case Magic('@'): | 1837 case Magic('@'): |
1838 { | 1838 { |
1839 int lop = END; | 1839 int lop = END; |
1840 int nr; | 1840 long nr; |
1841 | 1841 |
1842 nr = getdecchrs(); | 1842 nr = getdecchrs(); |
1843 switch (no_Magic(getchr())) | 1843 switch (no_Magic(getchr())) |
1844 { | 1844 { |
1845 case '=': lop = MATCH; break; /* \@= */ | 1845 case '=': lop = MATCH; break; /* \@= */ |
2276 case 'o': /* %o123 octal */ | 2276 case 'o': /* %o123 octal */ |
2277 case 'x': /* %xab hex 2 */ | 2277 case 'x': /* %xab hex 2 */ |
2278 case 'u': /* %uabcd hex 4 */ | 2278 case 'u': /* %uabcd hex 4 */ |
2279 case 'U': /* %U1234abcd hex 8 */ | 2279 case 'U': /* %U1234abcd hex 8 */ |
2280 { | 2280 { |
2281 int i; | 2281 long i; |
2282 | 2282 |
2283 switch (c) | 2283 switch (c) |
2284 { | 2284 { |
2285 case 'd': i = getdecchrs(); break; | 2285 case 'd': i = getdecchrs(); break; |
2286 case 'o': i = getoctchrs(); break; | 2286 case 'o': i = getoctchrs(); break; |
3272 * blahblah\%x20asdf | 3272 * blahblah\%x20asdf |
3273 * before-^ ^-after | 3273 * before-^ ^-after |
3274 * The parameter controls the maximum number of input characters. This will be | 3274 * The parameter controls the maximum number of input characters. This will be |
3275 * 2 when reading a \%x20 sequence and 4 when reading a \%u20AC sequence. | 3275 * 2 when reading a \%x20 sequence and 4 when reading a \%u20AC sequence. |
3276 */ | 3276 */ |
3277 static int | 3277 static long |
3278 gethexchrs(int maxinputlen) | 3278 gethexchrs(int maxinputlen) |
3279 { | 3279 { |
3280 int nr = 0; | 3280 long_u nr = 0; |
3281 int c; | 3281 int c; |
3282 int i; | 3282 int i; |
3283 | 3283 |
3284 for (i = 0; i < maxinputlen; ++i) | 3284 for (i = 0; i < maxinputlen; ++i) |
3285 { | 3285 { |
3291 ++regparse; | 3291 ++regparse; |
3292 } | 3292 } |
3293 | 3293 |
3294 if (i == 0) | 3294 if (i == 0) |
3295 return -1; | 3295 return -1; |
3296 return nr; | 3296 return (long)nr; |
3297 } | 3297 } |
3298 | 3298 |
3299 /* | 3299 /* |
3300 * Get and return the value of the decimal string immediately after the | 3300 * Get and return the value of the decimal string immediately after the |
3301 * current position. Return -1 for invalid. Consumes all digits. | 3301 * current position. Return -1 for invalid. Consumes all digits. |
3302 */ | 3302 */ |
3303 static int | 3303 static long |
3304 getdecchrs(void) | 3304 getdecchrs(void) |
3305 { | 3305 { |
3306 int nr = 0; | 3306 long_u nr = 0; |
3307 int c; | 3307 int c; |
3308 int i; | 3308 int i; |
3309 | 3309 |
3310 for (i = 0; ; ++i) | 3310 for (i = 0; ; ++i) |
3311 { | 3311 { |
3318 curchr = -1; /* no longer valid */ | 3318 curchr = -1; /* no longer valid */ |
3319 } | 3319 } |
3320 | 3320 |
3321 if (i == 0) | 3321 if (i == 0) |
3322 return -1; | 3322 return -1; |
3323 return nr; | 3323 return (long)nr; |
3324 } | 3324 } |
3325 | 3325 |
3326 /* | 3326 /* |
3327 * get and return the value of the octal string immediately after the current | 3327 * get and return the value of the octal string immediately after the current |
3328 * position. Return -1 for invalid, or 0-255 for valid. Smart enough to handle | 3328 * position. Return -1 for invalid, or 0-255 for valid. Smart enough to handle |
3329 * numbers > 377 correctly (for example, 400 is treated as 40) and doesn't | 3329 * numbers > 377 correctly (for example, 400 is treated as 40) and doesn't |
3330 * treat 8 or 9 as recognised characters. Position is updated: | 3330 * treat 8 or 9 as recognised characters. Position is updated: |
3331 * blahblah\%o210asdf | 3331 * blahblah\%o210asdf |
3332 * before-^ ^-after | 3332 * before-^ ^-after |
3333 */ | 3333 */ |
3334 static int | 3334 static long |
3335 getoctchrs(void) | 3335 getoctchrs(void) |
3336 { | 3336 { |
3337 int nr = 0; | 3337 long_u nr = 0; |
3338 int c; | 3338 int c; |
3339 int i; | 3339 int i; |
3340 | 3340 |
3341 for (i = 0; i < 3 && nr < 040; ++i) | 3341 for (i = 0; i < 3 && nr < 040; ++i) |
3342 { | 3342 { |
3348 ++regparse; | 3348 ++regparse; |
3349 } | 3349 } |
3350 | 3350 |
3351 if (i == 0) | 3351 if (i == 0) |
3352 return -1; | 3352 return -1; |
3353 return nr; | 3353 return (long)nr; |
3354 } | 3354 } |
3355 | 3355 |
3356 /* | 3356 /* |
3357 * Get a number after a backslash that is inside []. | 3357 * Get a number after a backslash that is inside []. |
3358 * When nothing is recognized return a backslash. | 3358 * When nothing is recognized return a backslash. |
3359 */ | 3359 */ |
3360 static int | 3360 static int |
3361 coll_get_char(void) | 3361 coll_get_char(void) |
3362 { | 3362 { |
3363 int nr = -1; | 3363 long nr = -1; |
3364 | 3364 |
3365 switch (*regparse++) | 3365 switch (*regparse++) |
3366 { | 3366 { |
3367 case 'd': nr = getdecchrs(); break; | 3367 case 'd': nr = getdecchrs(); break; |
3368 case 'o': nr = getoctchrs(); break; | 3368 case 'o': nr = getoctchrs(); break; |