diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index c340e32..e4b11fd 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -541,6 +541,9 @@ class Item_func_trim :public Item_str_func
   String remove;
   String *trimmed_value(String *res, uint32 offset, uint32 length)
   {
+    if (length == 0)
+      return make_empty_result();
+
     tmp_value.set(*res, offset, length);
     /*
       Make sure to return correct charset and collation:
