-
Notifications
You must be signed in to change notification settings - Fork 2
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
Clean #40
Clean #40
Changes from all commits
a8322e3
838b32c
a7f1601
4a0be4f
c341cbe
fe7991f
98f74dc
3ee2fde
4b2f6f9
10a5aab
0400eb7
fdbe60b
0bffa18
08eaef6
f39393b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
func main() { | ||
myAssemblyFunction() | ||
} | ||
|
||
asmf myAssemblyFunction() { | ||
0xB8 0x4C 0x00 0x00 0x00 0xC3 | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,6 @@ | |
// Version | ||
#define VERSION "0.1.0" | ||
|
||
uint8_t code_section[6] = { | ||
0xB8, 0x4C, 0x00, 0x00, 0x00, 0xC3 | ||
}; | ||
|
||
void showCommandEntry(char* commandName, char* description, int argumentCount, char* argumentNames[], char* argumentDescriptions[]) { | ||
printf("\n > %s\n\n %s%sDescription%s: %s\n", commandName, STYLE_BOLD, STYLE_UNDERLINE, RESET, description); | ||
|
||
|
@@ -117,8 +113,8 @@ int main(int argc, char* argv[]) { | |
buff[size] = '\0'; | ||
fclose(fptr); | ||
|
||
struct LexerResult result = runLexer(buff, size); | ||
struct ASTNode* root = parseNodes(result, 0, AST_ROOT); | ||
LEXER_RESULT result = runLexer(buff, size); | ||
AST_NODE* root = parseNodes(result, 0, AST_ROOT); | ||
Comment on lines
+116
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Potential null pointer and memory safety issues detected The code has several safety issues that need to be addressed:
Recommendations:
🔗 Analysis chainCheck potential null pointer usage. You can confirm correct handling by searching for additional checks of Let me gather more information about the Let me check how 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Searching for any checks on the result structure or parseNodes usage
# to ensure safety when runLexer fails or returns invalid data.
rg -A 5 $'parseNodes'
Length of output: 1983 Script: #!/bin/bash
# Check the LEXER_RESULT structure definition and runLexer implementation
ast-grep --pattern 'typedef struct $_ {
$$$
} LEXER_RESULT;'
rg -A 5 'runLexer\('
Length of output: 1780 Script: #!/bin/bash
# Check parseNodes implementation and token access
rg -A 10 'for\(.+; index <= result\.size;'
# Check if there's any error handling in lexer.c
rg -A 5 'malloc.*TOKEN.*1024' src/lexer/lexer.c
Length of output: 186 |
||
|
||
IR_CTX* ctx = makeContext(root); | ||
|
||
|
@@ -129,9 +125,7 @@ int main(int argc, char* argv[]) { | |
|
||
fptr = fopen(outputFile, "w"); | ||
compile(ctx, fptr); | ||
|
||
//compilePE(fptr, code_section, sizeof(code_section)); | ||
|
||
|
||
break; | ||
case 'v': | ||
if(strlen(argv[1]) > 1 && strcmp(argv[1], "version") != 0) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
* Quickfall PE Format Defintion. | ||
*/ | ||
|
||
#include "../units.h" | ||
|
||
#ifndef PE_FORMAT | ||
#define PE_FORMAT | ||
|
||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#ifndef TOKENS_H | ||
#define TOKENS_H | ||
|
||
enum TokenType { | ||
typedef enum { | ||
ASM_FUNCTION, | ||
FUNCTION, | ||
RETURN, | ||
|
@@ -23,15 +23,15 @@ enum TokenType { | |
USE, | ||
NONE, | ||
MATH_OP | ||
}; | ||
} TOKEN_TYPE; | ||
|
||
/** | ||
* An lexer token generated by the Lexer. | ||
*/ | ||
struct Token { | ||
enum TokenType type; | ||
typedef struct { | ||
TOKEN_TYPE type; | ||
char* value; | ||
}; | ||
} TOKEN; | ||
Comment on lines
+31
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Memory management issues confirmed in token handling The code review reveals several critical memory management issues:
Note: The codebase needs a proper memory management strategy with:
🔗 Analysis chainConsider adding safeguards for string value management The
Let's check how the value field is managed in the codebase: Let's search for more specific patterns in the implementation to understand how tokens are handled. Let's examine the lexer implementation to understand how tokens are created and managed. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for TOKEN value field allocations and deallocations
echo "Searching for value field memory management..."
rg -A 2 "token\.(value|->value)\s*=\s*"
rg -A 2 "free\s*\(\s*token\.(value|->value)\s*\)"
Length of output: 196 Script: #!/bin/bash
# Let's try a different approach to find TOKEN usage patterns
echo "Searching for TOKEN struct usage..."
rg -A 5 "TOKEN\s+\w+\s*="
echo -e "\nSearching for malloc/strdup with TOKEN..."
rg -A 3 "(malloc|strdup).*TOKEN"
echo -e "\nSearching for free with TOKEN..."
rg -B 2 -A 2 "free.*TOKEN"
echo -e "\nLooking for lexer implementation files..."
fd "lexer.*\.(c|h)$"
Length of output: 2440 Script: #!/bin/bash
# Let's examine the lexer implementation
echo "Checking lexer.c content..."
cat src/lexer/lexer.c
echo -e "\nChecking lexer.h content..."
cat src/lexer/lexer.h
echo -e "\nLooking for token cleanup/destruction..."
rg -B 3 -A 3 "cleanup|destroy|free" src/lexer/
Length of output: 3845 |
||
|
||
|
||
#endif |
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.
💡 Codebase verification
Memory leak detected in lexer implementation
The code review has revealed two memory leaks:
result.tokens
is allocated withmalloc
inrunLexer
but never freed after usebuff
is allocated withmalloc
but never freedSpecific locations:
src/lexer/lexer.c
:result.tokens = malloc(sizeof(TOKEN) * 1024)
src/lexer/lexer.c
:char* buff = malloc(buffLen)
inside the loopbenchmarks/main.c:126
: Theresult
fromrunLexer
is used but its memory is not freedtests/lexer.c
: The test also doesn't free the allocated memory🔗 Analysis chain
Confirm memory deallocation.
After using
LEXER_RESULT result
, confirm that any dynamically allocated fields withinresult
are freed, if relevant. This ensures we avoid memory leaks in multiple runs.Let me gather more information about the LEXER_RESULT structure and its memory management.
Let me try a different approach to find the structure and memory management patterns.
Let me check the lexer implementation files to understand the memory management better.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 58
Script:
Length of output: 144
Script:
Length of output: 735
Script:
Length of output: 3969