From 8af1dffb2ecb0b7fa7e237c8d4057d81db3ec5b3 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Thu, 5 Nov 2009 18:40:21 +0200 Subject: [PATCH] core: Safer slicing of search results --- src/rygel/rygel-media-container.vala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala index 0d1691f..8f05b2c 100644 --- a/src/rygel/rygel-media-container.vala +++ b/src/rygel/rygel-media-container.vala @@ -136,15 +136,18 @@ public abstract class Rygel.MediaContainer : MediaObject { // See if we need to slice the results if (total_matches > 0 && (offset != 0 || max_count != 0)) { + uint start; uint stop; + start = offset.clamp (0, total_matches - 1); + if (max_count != 0) { - stop = offset + max_count; + stop = start + max_count; } else { stop = total_matches - 1; } - return result.slice ((int) offset, (int) stop); + return result.slice ((int) start, (int) stop); } else { return result; } -- 2.7.4