-
Couldn't load subscription status.
- Fork 7
Code improvements #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code improvements #228
Conversation
| uint8 *cp; | ||
| uint32 lowpc, highpc, text_start; | ||
| uint32 lowpc, highpc; | ||
| uint32 text_start = 0; |
There was a problem hiding this comment.
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) ; |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memory leak
library/unistd/common_pathconf.c
Outdated
| break; | ||
| case _PC_MAX_INPUT: { | ||
| uint32_t Bufsize; | ||
| uint32_t Bufsize = 0L; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
|
so many leaks plugged...here's hoping |
|
Unfortuntely all those memory leaks are in tests file.. :( |
|
ah, ok shows how much I understand of coding |
|
Half of the memory leak fixes are in the clib4 library, and to be more specific in the following files |
I did a few code improvements based on the compiler warnings produced and the cppcheck report after running it on the library folder.