fix: null-safe bux_strcmp/bux_strncmp/bux_strcpy, init alloca typeName — project build no longer crashes
This commit is contained in:
@@ -170,6 +170,7 @@ func Lcx_LowerStmt(ctx: *LowerCtx, stmt: *Stmt) -> *HirNode {
|
|||||||
alloca.column = col;
|
alloca.column = col;
|
||||||
alloca.strValue = stmt.strValue;
|
alloca.strValue = stmt.strValue;
|
||||||
// Set type from the declared type expression
|
// Set type from the declared type expression
|
||||||
|
alloca.typeName = "";
|
||||||
if stmt.refStmtType != null as *TypeExpr {
|
if stmt.refStmtType != null as *TypeExpr {
|
||||||
alloca.intValue = stmt.refStmtType.kind;
|
alloca.intValue = stmt.refStmtType.kind;
|
||||||
alloca.typeName = stmt.refStmtType.typeName;
|
alloca.typeName = stmt.refStmtType.typeName;
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ func Lcx_LowerStmt(ctx: *LowerCtx, stmt: *Stmt) -> *HirNode {
|
|||||||
alloca.column = col;
|
alloca.column = col;
|
||||||
alloca.strValue = stmt.strValue;
|
alloca.strValue = stmt.strValue;
|
||||||
// Set type from the declared type expression
|
// Set type from the declared type expression
|
||||||
|
alloca.typeName = "";
|
||||||
if stmt.refStmtType != null as *TypeExpr {
|
if stmt.refStmtType != null as *TypeExpr {
|
||||||
alloca.intValue = stmt.refStmtType.kind;
|
alloca.intValue = stmt.refStmtType.kind;
|
||||||
alloca.typeName = stmt.refStmtType.typeName;
|
alloca.typeName = stmt.refStmtType.typeName;
|
||||||
|
|||||||
@@ -144,14 +144,21 @@ unsigned int bux_strlen(const char* s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int bux_strcmp(const char* a, const char* b) {
|
int bux_strcmp(const char* a, const char* b) {
|
||||||
|
if (a == b) return 0;
|
||||||
|
if (!a) return -1;
|
||||||
|
if (!b) return 1;
|
||||||
return strcmp(a, b);
|
return strcmp(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bux_strncmp(const char* a, const char* b, unsigned int n) {
|
int bux_strncmp(const char* a, const char* b, unsigned int n) {
|
||||||
|
if (a == b) return 0;
|
||||||
|
if (!a) return -1;
|
||||||
|
if (!b) return 1;
|
||||||
return strncmp(a, b, (size_t)n);
|
return strncmp(a, b, (size_t)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* bux_strcpy(char* dest, const char* src) {
|
char* bux_strcpy(char* dest, const char* src) {
|
||||||
|
if (!dest || !src) return dest;
|
||||||
return strcpy(dest, src);
|
return strcpy(dest, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user