/* Don't go past the length requested */
if (off_i + toappend > offset + length) {
- toappend = offset + length - off_i;
+ toappend = MIN(offset + length - off_i, flength - off_i);
}
ast_str_append_substr(buf, len, fbuf, toappend);
/* No length */
{ "123456789", "-5", "56789" },
{ "123456789", "4", "56789" },
+ /* Passed file length */
+ { "123456789", "8,10", "9" },
+ { "123456789", "10,1", "" },
+ /* Middle of file */
+ { "123456789", "2,5", "34567" },
+ { "123456789", "-7,5", "34567" },
/* Line mode, 4 ways of specifying the first character */
{ "123\n456\n789\n", "0,1,l", "123\n" },
{ "123\n456\n789\n", "-3,1,l", "123\n" },