Skip to content

Commit

Permalink
Merge pull request #121 from AleksArt000/main
Browse files Browse the repository at this point in the history
fixed variable parsing
  • Loading branch information
AleksArt000 authored Nov 10, 2024
2 parents 3a9d846 + 8933300 commit 258c13b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int readConfig(const char* configFilePath, int overwrite)
line[strlen(line) - 1] = 0;
parse_env(&line);

if((line[0] != '#' || (line[0] != '/' && line[1] != '/')) && strstr(line, "=") != 0)
if(((line[0] != '#') && ((line[0] != '/') && (line[1] != '/'))) && (strstr(line, "=") != 0))
{
char* key = strtok(line, "=");
char* value = strchr(line, '\0') + 1;
Expand Down
71 changes: 36 additions & 35 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,38 @@ int f_install_package_source(const char* spm_path, int as_dep, char* repo) {
QUEUE_COUNT++;
dbg(1, "Added %s to the queue", pkg.name);

// Set the package info section as environment vadiables for make script
setenv("NAME", pkg.name, 1);
setenv("VERSION", pkg.version, 1);

// Get global environment variables
if (pkg.url != NULL)
{
parse_env(&(pkg.url));
dbg(1, "URL: %s", pkg.url);
setenv("URL", pkg.url, 1);
}

if (pkg.type != NULL)
{
setenv("TYPE", pkg.type, 1);
}

if (pkg.license != NULL)
{
setenv("LICENSE", pkg.license, 1);
}

if (pkg.sha256 != NULL)
{
setenv("SHA256", pkg.sha256, 1);
}

// Set environment variables for building
setenv("BUILD_ROOT", build_dir, 1);

/* Warning: there is something sussy going on beyond this point */

// Get global environment variables
if (pkg.environment != NULL)
{
dbg(1, "Getting environment variables...");
Expand All @@ -88,7 +117,6 @@ int f_install_package_source(const char* spm_path, int as_dep, char* repo) {
}

// Set global environment variables

if (pkg.exports != NULL && pkg.exportsCount > 0 && strlen(pkg.exports[0]) > 0)

Check warning on line 120 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:120:9 [clang-analyzer-unix.Malloc]

Potential leak of memory pointed to by 'env_path'
{
dbg(1, "Setting environment variables...");
Expand All @@ -101,11 +129,13 @@ int f_install_package_source(const char* spm_path, int as_dep, char* repo) {
for (int i = 0; i < pkg.exportsCount; i++)
{
fprintf(env_file, "%s\n", pkg.exports[i]);
char* line = strdup(pkg.exports[i]);
parse_env(&line);

if((pkg.exports[i][0] != '#' || (pkg.exports[i][0] != '/' && pkg.exports[i][1] != '/')) && strstr(pkg.exports[i], "=") != 0)
if(((line[0] != '#') && ((line[0] != '/') && (line[1] != '/'))) && (strstr(line, "=") != 0))
{
char* key = strtok(pkg.exports[i], "=");
char* value = strchr(pkg.exports[i], '\0') + 1;
char* key = strtok(line, "=");
char* value = strchr(line, '\0') + 1;

if (key == NULL || value == NULL)
{
Expand All @@ -117,41 +147,12 @@ int f_install_package_source(const char* spm_path, int as_dep, char* repo) {
// Set environment variables based on the key-value pairs in the config file
setenv(key, value, 1);

Check warning on line 148 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:148:17 [clang-analyzer-core.NonNullParamChecker]

Null pointer passed to 2nd parameter expecting 'nonnull'
}
free(line);
}

fclose(env_file);
}

// Set the package info section as environment vadiables for make script

setenv("NAME", pkg.name, 1);
setenv("VERSION", pkg.version, 1);

if (pkg.url != NULL)
{
parse_env(&(pkg.url));
dbg(1, "URL: %s", pkg.url);
setenv("URL", pkg.url, 1);
}

if (pkg.type != NULL)
{
setenv("TYPE", pkg.type, 1);
}

if (pkg.license != NULL)
{
setenv("LICENSE", pkg.license, 1);
}

if (pkg.sha256 != NULL)
{
setenv("SHA256", pkg.sha256, 1);
}

// Set environment variables for building
setenv("BUILD_ROOT", build_dir, 1);


// Check if a package is a collection
if(strcmp(pkg.type, "con") != 0)

Check warning on line 158 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:158:8 [clang-analyzer-core.NonNullParamChecker]

Null pointer passed to 1st parameter expecting 'nonnull'
Expand Down
2 changes: 2 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ void test_split() {
free(*split_list);
free(split_list);

dbg(2, "str_split: %s", str_split);
dbg(2, "split_str: %s", split_str);

assert(strcmp(str_split,split_str) == 0);

Expand Down

0 comments on commit 258c13b

Please sign in to comment.