Mercurial > vim
comparison src/scriptfile.c @ 28903:6a7d94628b5a v8.2.4974
patch 8.2.4974: ":so" command may read after end of buffer
Commit: https://github.com/vim/vim/commit/4748c4bd64610cf943a431d215bb1aad51f8d0b4
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 17 17:47:07 2022 +0100
patch 8.2.4974: ":so" command may read after end of buffer
Problem: ":so" command may read after end of buffer.
Solution: Compute length of text properly.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 17 May 2022 19:00:03 +0200 |
parents | 4dcccb2673fe |
children | a74398c432a4 |
comparison
equal
deleted
inserted
replaced
28902:26d0d6f9b368 | 28903:6a7d94628b5a |
---|---|
1963 sp->buf_lnum++; | 1963 sp->buf_lnum++; |
1964 if (ga_grow(&ga, 1) == FAIL) | 1964 if (ga_grow(&ga, 1) == FAIL) |
1965 break; | 1965 break; |
1966 buf = (char_u *)ga.ga_data; | 1966 buf = (char_u *)ga.ga_data; |
1967 buf[ga.ga_len++] = NUL; | 1967 buf[ga.ga_len++] = NUL; |
1968 len = ga.ga_len; | |
1968 } | 1969 } |
1969 else | 1970 else |
1970 { | 1971 { |
1971 buf = (char_u *)ga.ga_data; | 1972 buf = (char_u *)ga.ga_data; |
1972 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, | 1973 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, |
1973 sp->fp) == NULL) | 1974 sp->fp) == NULL) |
1974 break; | 1975 break; |
1975 } | 1976 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); |
1976 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); | 1977 } |
1977 #ifdef USE_CRNL | 1978 #ifdef USE_CRNL |
1978 // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the | 1979 // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the |
1979 // CTRL-Z by its own, or after a NL. | 1980 // CTRL-Z by its own, or after a NL. |
1980 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) | 1981 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) |
1981 && sp->fileformat == EOL_DOS | 1982 && sp->fileformat == EOL_DOS |