]> git.cworth.org Git - mnemon/commitdiff
Avoid unnecessary (and potentially dangerous) memmove
authorCarl Worth <cworth@cworth.org>
Tue, 17 Apr 2007 22:34:27 +0000 (15:34 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 17 Apr 2007 22:34:27 +0000 (15:34 -0700)
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. */
     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);
     mnemon->num_bins++;
 
     bin_init (bin, count);