Skip to content

Conversation

@walkero-gr
Copy link
Contributor

I did a few code improvements based on the compiler warnings produced and the cppcheck report after running it on the library folder.

uint8 *cp;
uint32 lowpc, highpc, text_start;
uint32 lowpc, highpc;
uint32 text_start = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text_start was not initialised and when if (low_pc == 0 && high_pc == 0) { was false this had no initial value at p->text_start = text_start; on line 175

# ifdef D
# undef D
# endif // D
#define D(x) ;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler was complaining the the D is redefined

if (res) {
struct Clib4Node c2n;
char varbuf[8] = {0};
char uuid[UUID4_LEN + 1] = {0};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were not used anywhere

libBase->libNode.lib_Version = VERSION;
libBase->libNode.lib_Revision = REVISION;
libBase->libNode.lib_IdString = VSTRING;
libBase->libNode.lib_IdString = (char *)VSTRING;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler was complaining for losing the const character

int clib4ProcessCompare(const void *a, const void *b, void *udata);

static void _start_ctors(void (*__CTOR_LIST__[])(void));
static void _start_dtors(void (*__DTOR_LIST__[])(void));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were set here but were not defined. These are defined and used in main.c, so I thought that they are not needed here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this please. Don't touch them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afxgroup With my last commit I reverted those changes.

int saw_digit, octets, ch;
unsigned char tmp[NS_INADDRSZ], *tp;
unsigned char tmp[NS_INADDRSZ] = {0};
unsigned char *tp;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tmp was not initialised and later, based on conditions, an initial value is required

}
ret2 = vsnprintf(ptr, ret, format, ap);
if (ret2 < 0) {
free(ptr);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory leak

bp = (char *) malloc(malloc_size);
if (bp == NULL) {
__set_errno(ENOMEM);
free(buf.beg);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory leak

break;
case _PC_MAX_INPUT: {
uint32_t Bufsize;
uint32_t Bufsize = 0L;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bufsize was not initialised and later, based on conditions, an initial value is required, but I am not sure about the value I put here. Is that right?

Copy link
Member

@3246251196 3246251196 Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be UL, but it depends on the architecture if L is actually needed. int is normally a target's natural word size, but also can be as low as 16bits. Perhaps U would work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@3246251196 With my last commit, I changed this to 2048, because a few lines later (line 127) there is this comment ret = Bufsize; /* Default is 2048 bytes. */

host_entity = gethostbyname(addr_host);
if (host_entity == NULL) {
// No ip found for hostname
free(ip);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory leak

printf( "Length in bytes of multibyte character %x: %u\n", pmb, len );


free(pwcs);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory leaks fixes

free(pwcs);
}

free(pmb);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory leak fix

return;
}

ar[n] = tmp;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these changes the following critical error is fixed, referring to this line.

Address of local auto-variable assigned to a function parameter.

@raziel-
Copy link
Contributor

raziel- commented Dec 18, 2024

so many leaks plugged...here's hoping

@afxgroup
Copy link
Collaborator

Unfortuntely all those memory leaks are in tests file.. :(

@afxgroup afxgroup merged commit 34c7e75 into AmigaLabs:development Dec 18, 2024
@raziel-
Copy link
Contributor

raziel- commented Dec 18, 2024

ah, ok

shows how much I understand of coding

@walkero-gr
Copy link
Contributor Author

Half of the memory leak fixes are in the clib4 library, and to be more specific in the following files
library/stdio/vdprintf.c
library/stdlib/qsort_r.c
library/termcap/termcap.c

@walkero-gr walkero-gr deleted the code-improvements branch December 18, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants