cancel
Showing results for 
Search instead for 
Did you mean: 

Bus fault Imprecise error

sirpak
Associate II

Dear Sirs,

I want to edit a string, but the system goes to hard fault (bus fault Imprecise error).

Here below the code:

typedef struct CC_PACKED
{
...
const char *name;
...
} _objd;

static const char acName2005_19[] = "Cycle 0 delta stop";

const _objd SDO2005[] =

{....

{0x19, DTYPE_UNSIGNED32, 32, ATYPE_RW | ATYPE_RXPDO, acName2005_19, 0, 0, MAX_U32, 0, &Modbus_register, C_2005_2006_x_R, C_2005_2006_x_W},

};

in a separate function, since the name is const, I transfer the string to the RAM memory and I try to edit it:

const _objd* objd = ....;

char* s;

u8 name_length = strlen(objd->name) + 1;

s = (char*)malloc(name_length);

strcpy(s, (objd + nsub)->name);

the strcpy sends me in hard fault.

Anybody can please help?

13 REPLIES 13
Pavel A.
Evangelist III

With method #2, where it fails? at which index?

Perhaps your malloc() is broken (allocates from wrong memory). Try to copy to a static array.

 

Still not working 🤔..

I removed the free() at the end of the function, and it seemed to work.

It worked only once, the second time I test the code, it crashes. Maybe because the heap gets full?!

Dear All,

thank you for your help.

I removed the malloc and I used an array of char with fixed size and all is working fine.

I use 4 kB of heap and 4 kB of stack.

Total SRAM memory is 64 kB.

Maybe I have some problem with memory allocation and it does not allow me to allocate it dynamically..

 

Looks so. 4K heap, and 64KB total, with the GNU library isn't serious.