lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Roberto Ierusalimschy wrote:

void *l_alloc (void *ud, void *block, size_t oldsize, size_t size) {
  if (size == 0) {
    free(block);
    return NULL;
  }
  else {
    void *newblock = malloc(size);  /* alloc a new block */
    if (newblock == NULL) return NULL;
    if (block) {
      size_t commonsize = (oldsize < size) ? oldsize : size;
      memcpy(newblock, block, commonsize);
      free(block);
    }
    return newblock;
  }
}

Wouldn't it be better to do nothing and just return 'block' if (size <= oldsize) ?
(or am I missing something here?)

  Enrico