jtsiomb / kdtree

A simple C library for working with KD-Trees
http://nuclear.mutantstargoat.com/sw/kdtree/
Other
395 stars 115 forks source link

kd_res_item doesn't properly copy pos #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Within the function is a commented description of the problem as well as a
suggested patch.  Hope this helps.

void *kd_res_item(void *set, double *pos)
{
  struct result_set *rset = (struct result_set*)set;

  if(rset->riter) {
    if(pos) {
      //The number of bytes copied is d.  However, this assumes one byte 
      //  per double.  The third argument to memcpy should be 
      //  rset->tree->dim * sizeof(double) so that the correct number 
      //  of bytes are copied
      //original: memcpy(pos, rset->riter->item->pos, rset->tree->dim);
      memcpy(pos, rset->riter->item->pos, rset->tree->dim *
sizeof(double));       
    }
    return rset->riter->item->data;
  }
  return 0;
}

Original issue reported on code.google.com by dound07 on 24 Jul 2007 at 7:20

GoogleCodeExporter commented 9 years ago
Of course it wasn't an "assumption" as such of one-byte-per-double, as that 
would be
a rather unreasonable assumption. I just forgot the sizeof :)

Thank you for your bug report, I did the necessary changes.

Original comment by jtsi...@gmail.com on 25 Jul 2007 at 12:24