Skip to content

Commit

Permalink
[NARS1] [estess] Eliminate longcpy usages with memcpy; Fix edge case …
Browse files Browse the repository at this point in the history
…in lv_getslot YottaDB#80

These changes address review comments

1) All longcpy usages need to be replaced with memcpy. Since there were only a few remaining in the codebase, I replaced all of them.
2) lv_getslot.c : In function lvtreenode_getslot(), as soon as numElems is > (MAXINT4 / 2) but is < MAXINT4, we would end up passing a number that is > MAXINT4 but < MAXUINT4 to lvtreenode_newblock(). The latter expects a signed int though and so is going to see this as a negative number. Fix it so we never pass more than MAXINT4 to lvtreenode_newblock(). While in this module, fix a few assignments to be DEBUG_ONLY and move them to their proper scope and add a few missing asserts in lv_getslot() similar to the other two (lvtree_getslot() and lvtreenode_getslot()).
  • Loading branch information
nars1 committed Nov 10, 2017
1 parent 3ebe73e commit e4bea09
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 43 deletions.
6 changes: 4 additions & 2 deletions sr_port/lke_show.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) 2001-2017 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2017 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
Expand Down Expand Up @@ -33,7 +36,6 @@
#include "hashtab_mname.h" /* needed for cmmdef.h */
#include "cmmdef.h" /* for gtcmtr_protos.h */
#include "util.h"
#include "longcpy.h"
#include "gtcmtr_protos.h"
#include "lke.h"
#include "lke_getcli.h"
Expand Down Expand Up @@ -113,7 +115,7 @@ void lke_show(void)
/* Prevent any modification of the lock space while we make a local copy of it */
if (!nocrit)
GRAB_LOCK_CRIT(csa, reg, was_crit);
longcpy((uchar_ptr_t)ctl, (uchar_ptr_t)csa->lock_addrs[0], ls_len);
memcpy((uchar_ptr_t)ctl, (uchar_ptr_t)csa->lock_addrs[0], ls_len);
assert((ctl->max_blkcnt > 0) && (ctl->max_prccnt > 0) && ((ctl->subtop - ctl->subbase) > 0));
if (!nocrit)
REL_LOCK_CRIT(csa, reg, was_crit);
Expand Down
28 changes: 0 additions & 28 deletions sr_port/longcpy.h

This file was deleted.

10 changes: 6 additions & 4 deletions sr_port/lv_getslot.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ lv_val *lv_getslot(symval *sym)
lv_val *lv;
unsigned int numElems, numUsed;

numElems = MAXUINT4; /* maximum value */
if (lv = sym->lv_flist)
{
assert(NULL == LV_PARENT(lv)); /* stp_gcol relies on this for correct garbage collection */
sym->lv_flist = (lv_val *)lv->ptrs.free_ent.next_free;
} else
{
DEBUG_ONLY(numElems = MAXUINT4); /* maximum value */
for (p = sym->lv_first_block; ; p = p->next)
{
if (NULL == p)
Expand All @@ -71,6 +71,8 @@ lv_val *lv_getslot(symval *sym)
p->numUsed++;
break;
}
assert(numElems >= p->numAlloc);
DEBUG_ONLY(numElems = p->numAlloc);
}
}
assert(lv);
Expand All @@ -85,13 +87,13 @@ lvTree *lvtree_getslot(symval *sym)
lvTree *lvt;
unsigned int numElems, numUsed;

numElems = MAXUINT4; /* maximum value */
if (lvt = sym->lvtree_flist)
{
assert(NULL == LVT_GET_PARENT(lvt));
sym->lvtree_flist = (lvTree *)lvt->avl_root;
} else
{
DEBUG_ONLY(numElems = MAXUINT4); /* maximum value */
for (p = sym->lvtree_first_block; ; p = p->next)
{
if (NULL == p)
Expand Down Expand Up @@ -126,13 +128,13 @@ lvTreeNode *lvtreenode_getslot(symval *sym)
lvTreeNode *lv;
unsigned int numElems, numUsed;

numElems = MAXUINT4; /* maximum value */
if (lv = sym->lvtreenode_flist)
{
assert(NULL == LV_PARENT(lv)); /* stp_gcol relies on this for correct garbage collection */
sym->lvtreenode_flist = (lvTreeNode *)lv->sbs_child;
} else
{
DEBUG_ONLY(numElems = MAXUINT4); /* maximum value */
for (p = sym->lvtreenode_first_block; ; p = p->next)
{
if (NULL == p)
Expand All @@ -141,7 +143,7 @@ lvTreeNode *lvtreenode_getslot(symval *sym)
numElems = p->numAlloc;
else
numElems = LV_NEWBLOCK_INIT_ALLOC;
lvtreenode_newblock(sym, (numElems < MAXINT4) ? (numElems * 2) : MAXINT4);
lvtreenode_newblock(sym, (numElems <= (MAXINT4 / 2)) ? (numElems * 2) : MAXINT4);
p = sym->lvtreenode_first_block;
assert(NULL != p);
}
Expand Down
6 changes: 4 additions & 2 deletions sr_port/stp_expand_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
****************************************************************/

#include "mdef.h"

#include "gtm_string.h"

#include "compiler.h"
#include "stringpool.h"
#include "stp_parms.h"
#include "longcpy.h"

GBLREF mstr **stp_array;
GBLREF gtm_uint64_t stp_array_size;
Expand All @@ -30,7 +32,7 @@ void stp_expand_array(void)
stp_array_size = ((MAXINT4 > n) ? (n * 2) : (n + MAXINT4));
a = stp_array;
stp_array = (mstr **)malloc(stp_array_size * SIZEOF(mstr *));
longcpy((uchar_ptr_t)stp_array, (uchar_ptr_t)a, n * SIZEOF(mstr *));
memcpy((uchar_ptr_t)stp_array, (uchar_ptr_t)a, n * SIZEOF(mstr *));
free(a);
return;
}
1 change: 0 additions & 1 deletion sr_port/stp_gcol_src.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include "zshow.h"
#include "zwrite.h"
#include "error.h"
#include "longcpy.h"
#include "stpg_sort.h"
#include "hashtab_objcode.h"
#include "hashtab_str.h"
Expand Down
7 changes: 5 additions & 2 deletions sr_port/tp_hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) 2001-2017 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2017 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
Expand All @@ -13,6 +16,7 @@
#include "mdef.h"

#include "gtm_string.h"

#include "gdsroot.h"
#include "gdskill.h"
#include "gdsblk.h"
Expand All @@ -25,7 +29,6 @@
#include "copy.h"
#include "jnl.h"
#include "buddy_list.h" /* needed for tp.h */
#include "longcpy.h"
#include "hashtab_int4.h" /* needed for tp.h and cws_insert.h */
#include "tp.h"
#include "longset.h" /* needed for cws_insert.h */
Expand Down Expand Up @@ -496,7 +499,7 @@ void gds_tp_hist_moved(sgm_info *si, srch_hist *hist1)
assert(si->cur_tp_hist_size < si->tp_hist_size);
si->cur_tp_hist_size <<= 1;
new_first_tp_hist = (srch_blk_status *)malloc(SIZEOF(srch_blk_status) * si->cur_tp_hist_size);
longcpy((uchar_ptr_t)new_first_tp_hist, (uchar_ptr_t)si->first_tp_hist,
memcpy((uchar_ptr_t)new_first_tp_hist, (uchar_ptr_t)si->first_tp_hist,
(sm_uc_ptr_t)si->last_tp_hist - (sm_uc_ptr_t)si->first_tp_hist);
delta = (sm_long_t)((sm_uc_ptr_t)new_first_tp_hist - (sm_uc_ptr_t)si->first_tp_hist);
for (tabent = si->blks_in_use->base, topent = si->blks_in_use->top; tabent < topent; tabent++)
Expand Down
8 changes: 6 additions & 2 deletions sr_port_cm/gtcmtr_lke_showrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) 2001-2017 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2017 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
Expand All @@ -19,6 +22,8 @@

#include "mdef.h"

#include "gtm_string.h"

#include <stddef.h>

#include "cmidef.h"
Expand All @@ -39,7 +44,6 @@
#include "iosp.h"
#include "gtcm_find_region.h"
#include "gvcmz.h"
#include "longcpy.h"
#include "interlock.h"
#include "rel_quant.h"

Expand Down Expand Up @@ -68,7 +72,7 @@ char gtcmtr_lke_showrep(struct CLB *lnk, show_request *sreq)
lke_ctl = (mlk_ctldata *)malloc(ls_len);
/* Prevent any modification of the lock space while we make a local copy of it */
GRAB_LOCK_CRIT(csa, gv_cur_region, was_crit);
longcpy((uchar_ptr_t)lke_ctl, csa->lock_addrs[0], ls_len);
memcpy((uchar_ptr_t)lke_ctl, csa->lock_addrs[0], ls_len);
REL_LOCK_CRIT(csa, gv_cur_region, was_crit);
util_cm_print(lnk, 0, NULL, RESET);
dnode.len = sreq->nodelength;
Expand Down
6 changes: 4 additions & 2 deletions sr_port_cm/gtcmtr_lke_showreq.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/****************************************************************
* *
* Copyright 2001, 2009 Fidelity Information Services, Inc *
* Copyright 2001, 2009 Fidelity Information Services, Inc *
* *
* Copyright (c) 2017 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
Expand Down Expand Up @@ -40,7 +43,6 @@
#include "iosp.h"
#include "gtcm_find_region.h"
#include "gvcmz.h"
#include "longcpy.h"

#define FLUSH 1

Expand Down

0 comments on commit e4bea09

Please sign in to comment.