From 272d88460cae164fe310ba905c58e1834eb4eecd Mon Sep 17 00:00:00 2001 From: norly Date: Fri, 21 Jun 2013 00:41:14 +0100 Subject: [PATCH] Merge cloneScn() into reladd.c It's the only place where we use it, and it's case-specific --- include/libelfu/modelops.h | 2 -- src/libelfu/modelops/clone.c | 35 ----------------------------------- src/libelfu/modelops/reladd.c | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 38 deletions(-) delete mode 100644 src/libelfu/modelops/clone.c diff --git a/include/libelfu/modelops.h b/include/libelfu/modelops.h index e5702f7..3a5d7ea 100644 --- a/include/libelfu/modelops.h +++ b/include/libelfu/modelops.h @@ -52,8 +52,6 @@ void elfu_mRelocate(ElfuElf *metarget, ElfuScn *mstarget, ElfuScn *msrt); int elfu_mCheck(ElfuElf *me); -ElfuScn* elfu_mCloneScn(ElfuScn *ms); - void elfu_mDumpPhdr(ElfuElf *me, ElfuPhdr *mp); void elfu_mDumpScn(ElfuElf *me, ElfuScn *ms); diff --git a/src/libelfu/modelops/clone.c b/src/libelfu/modelops/clone.c deleted file mode 100644 index 8b9b0bc..0000000 --- a/src/libelfu/modelops/clone.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include - -ElfuScn* elfu_mCloneScn(ElfuScn *ms) -{ - ElfuScn *newscn; - - assert(ms); - - newscn = elfu_mScnAlloc(); - if (!newscn) { - ELFU_WARN("elfu_nCloneScn: Could not allocate memory for new ElfuScn.\n"); - return NULL; - } - - newscn->shdr = ms->shdr; - - if (ms->databuf) { - void *newbuf = malloc(ms->shdr.sh_size); - if (!newbuf) { - ELFU_WARN("elfu_nCloneScn: Could not allocate memory for new data buffer.\n"); - free(newscn); - return NULL; - } - - memcpy(newbuf, ms->databuf, ms->shdr.sh_size); - newscn->databuf = newbuf; - } - - newscn->oldptr = ms; - - return newscn; -} diff --git a/src/libelfu/modelops/reladd.c b/src/libelfu/modelops/reladd.c index 8c56d4f..6ab54e0 100644 --- a/src/libelfu/modelops/reladd.c +++ b/src/libelfu/modelops/reladd.c @@ -5,6 +5,37 @@ #include +static ElfuScn* cloneScn(ElfuScn *ms) +{ + ElfuScn *newscn; + + assert(ms); + + newscn = elfu_mScnAlloc(); + if (!newscn) { + return NULL; + } + + newscn->shdr = ms->shdr; + + if (ms->databuf) { + void *newbuf = malloc(ms->shdr.sh_size); + if (!newbuf) { + ELFU_WARN("cloneScn: Could not allocate memory for new data buffer.\n"); + free(newscn); + return NULL; + } + + memcpy(newbuf, ms->databuf, ms->shdr.sh_size); + newscn->databuf = newbuf; + } + + newscn->oldptr = ms; + + return newscn; +} + + static int appendData(ElfuScn *ms, void *buf, size_t len) { char *newbuf; @@ -36,7 +67,7 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn) ElfuPhdr *injPhdr; if (oldscn->shdr.sh_flags & SHF_ALLOC) { - newscn = elfu_mCloneScn(oldscn); + newscn = cloneScn(oldscn); if (!newscn) { return NULL; } -- 2.30.2