]> git.cworth.org Git - mnemon/blobdiff - mnemon.c
Avoid unnecessary (and potentially dangerous) memmove
[mnemon] / mnemon.c
index 45e09308e53f017bfc63905463c1be7469ee387d..25ba65fac17040f6b6600c6defa9d0bebcf1638f 100644 (file)
--- a/mnemon.c
+++ b/mnemon.c
@@ -372,7 +372,8 @@ mnemon_get_bin (mnemon_t    *mnemon,
     bin = &mnemon->bins[i];
 
     /* Make room to insert new bin at its sorted location. */
-    memmove (bin + 1, bin, (mnemon->num_bins - i) * sizeof (bin_t));
+    if (i < mnemon->num_bins)
+       memmove (bin + 1, bin, (mnemon->num_bins - i) * sizeof (bin_t));
     mnemon->num_bins++;
 
     bin_init (bin, count);