gallium: fix trim() function bug when count < first