X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afh.c;h=dd69d9e458d73ff9fbd9735f590b54a3b999922f;hp=86f34ace67e0efcba11fb9ddfe1a2f23ca2416b7;hb=2b471378b49c04db7bb84d1e75db981f91ad93db;hpb=087145d473a3956443e3ea50c48f5a104d43df5d;ds=sidebyside diff --git a/afh.c b/afh.c index 86f34ace..dd69d9e4 100644 --- a/afh.c +++ b/afh.c @@ -64,18 +64,26 @@ static int cat_file(void *audio_file_data, struct afh_info *afhi) size_t size; - if (conf.begin_chunk_arg < 0) - return -ERRNO_TO_PARA_ERROR(EINVAL); - first_chunk = conf.begin_chunk_arg; - - if (conf.end_chunk_given) { - if (conf.end_chunk_arg < 0) - return -ERRNO_TO_PARA_ERROR(EINVAL); - if (conf.end_chunk_arg >= afhi->chunks_total) + if (conf.begin_chunk_arg < 0) { + if (-conf.begin_chunk_arg > afhi->chunks_total) return -ERRNO_TO_PARA_ERROR(EINVAL); - last_chunk = conf.end_chunk_arg; + first_chunk = afhi->chunks_total + conf.begin_chunk_arg; + } else + first_chunk = conf.begin_chunk_arg; + if (conf.end_chunk_given) { + if (conf.end_chunk_arg < 0) { + if (-conf.end_chunk_arg > afhi->chunks_total) + return -ERRNO_TO_PARA_ERROR(EINVAL); + last_chunk = afhi->chunks_total + conf.end_chunk_arg; + } else { + if (conf.end_chunk_arg >= afhi->chunks_total) + return -ERRNO_TO_PARA_ERROR(EINVAL); + last_chunk = conf.end_chunk_arg; + } } else last_chunk = afhi->chunks_total - 1; + if (first_chunk >= last_chunk) + return -ERRNO_TO_PARA_ERROR(EINVAL); if (!afhi->chunks_total) return 1; afh_get_header(afhi, audio_file_data, &buf, &size);