mirror of
https://github.com/bobbimanners/GNO-Extras.git
synced 2025-03-12 06:29:39 +00:00
Fixed memory allocation bug!
This commit is contained in:
parent
ec0add343e
commit
9383a918f6
@ -345,7 +345,7 @@ int readdir(uint device, uint blocknum) {
|
|||||||
uchar blkcnt = 1;
|
uchar blkcnt = 1;
|
||||||
uint hdrblknum = blocknum;
|
uint hdrblknum = blocknum;
|
||||||
|
|
||||||
blocks = (struct block*)malloc(BLKSZ);
|
blocks = (struct block*)malloc(sizeof(struct block));
|
||||||
if (!blocks) {
|
if (!blocks) {
|
||||||
prerr("Unable to allocate memory");
|
prerr("Unable to allocate memory");
|
||||||
return 1;
|
return 1;
|
||||||
@ -461,7 +461,8 @@ int readdir(uint device, uint blocknum) {
|
|||||||
if (blkentries == entperblk) {
|
if (blkentries == entperblk) {
|
||||||
blocknum =
|
blocknum =
|
||||||
curblk->data[0x02] + 256U*curblk->data[0x03];
|
curblk->data[0x02] + 256U*curblk->data[0x03];
|
||||||
curblk->next = (struct block*)malloc(BLKSZ);
|
curblk->next =
|
||||||
|
(struct block*)malloc(sizeof(struct block));
|
||||||
if (!curblk->next) {
|
if (!curblk->next) {
|
||||||
prerr("Unable to allocate memory");
|
prerr("Unable to allocate memory");
|
||||||
return 1;
|
return 1;
|
||||||
@ -552,14 +553,13 @@ void copyent(uint srcblk, uint srcent, uint dstblk, uint dstent, uint device) {
|
|||||||
source = source->next;
|
source = source->next;
|
||||||
while (--dstblk > 0)
|
while (--dstblk > 0)
|
||||||
dest = dest->next;
|
dest = dest->next;
|
||||||
|
char *srcptr = source->data + PTRSZ + (srcent-1) * entsz;
|
||||||
char *dstptr = dest->sorteddata + PTRSZ + (dstent-1) * entsz;
|
char *dstptr = dest->sorteddata + PTRSZ + (dstent-1) * entsz;
|
||||||
memcpy(dstptr,
|
memcpy(dstptr, srcptr, entsz);
|
||||||
source->data + PTRSZ + (srcent-1) * entsz,
|
|
||||||
entsz);
|
|
||||||
|
|
||||||
/* For directories, update the parent dir entry number */
|
/* For directories, update the parent dir entry number */
|
||||||
if ((*dstptr & 0xf0) == 0xd0) {
|
|
||||||
struct pd_dirent *ent = (struct pd_dirent*)dstptr;
|
struct pd_dirent *ent = (struct pd_dirent*)dstptr;
|
||||||
|
if ((ent->typ_len & 0xf0) == 0xd0) {
|
||||||
uint block = ent->keyptr[0] + 256U * ent->keyptr[1];
|
uint block = ent->keyptr[0] + 256U * ent->keyptr[1];
|
||||||
if (readdiskblock(device, block, buf) == -1) {
|
if (readdiskblock(device, block, buf) == -1) {
|
||||||
prerr("Can't read subdirectory");
|
prerr("Can't read subdirectory");
|
||||||
@ -632,6 +632,18 @@ void usage(void) {
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void debuglinkedlist(void) {
|
||||||
|
puts("============================================");
|
||||||
|
struct block *b = blocks;
|
||||||
|
while (b) {
|
||||||
|
pr_uint((uint)b);
|
||||||
|
puts("----");
|
||||||
|
b = b->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
usage();
|
usage();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user