blob: 8b9b0bcea91f9b28b54c396b1f0cbc4b8eb52fc6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <libelfu/libelfu.h>
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;
}
|