Skip to content

feat(os_functions): loadenv builtin - #1477

Merged
Nelson-numerical-software merged 1 commit into
masterfrom
loadenv
Nov 1, 2025
Merged

Nelson-numerical-software merged 1 commit into
masterfrom
loadenv

Conversation

@Nelson-numerical-software

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +204 to +208

if (value.size() >= 2 && (value.front() == '"' && value.back() == '"')) {
return value.substr(1, value.size() - 2);
}

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

The strip_quotes function only handles double quotes but the .env file (sample.env) uses single quotes for all values. This will cause the quotes to not be stripped from the values. Add handling for single quotes: (value.front() == '\\'' && value.back() == '\\'') alongside the double quote check.

Suggested change
if (value.size() >= 2 && (value.front() == '"' && value.back() == '"')) {
return value.substr(1, value.size() - 2);
}
if (value.size() >= 2) {
if ((value.front() == '"' && value.back() == '"') ||
(value.front() == '\'' && value.back() == '\'')) {
return value.substr(1, value.size() - 2);
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +182 to +192

bool in_quotes = false;
std::string cleaned;

for (size_t i = 0; i < value.size(); ++i) {
char c = value[i];

if (c == '"')
in_quotes = !in_quotes;

if (!in_quotes && c == '#')

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

The remove_inline_comment function only tracks double quotes but not single quotes. If the .env file contains single-quoted values with '#' characters inside, they will be incorrectly treated as comments. Add tracking for single quotes as well.

Suggested change
bool in_quotes = false;
std::string cleaned;
for (size_t i = 0; i < value.size(); ++i) {
char c = value[i];
if (c == '"')
in_quotes = !in_quotes;
if (!in_quotes && c == '#')
bool in_single_quotes = false;
bool in_double_quotes = false;
std::string cleaned;
for (size_t i = 0; i < value.size(); ++i) {
char c = value[i];
if (c == '"' && !in_single_quotes)
in_double_quotes = !in_double_quotes;
else if (c == '\'' && !in_double_quotes)
in_single_quotes = !in_single_quotes;
if (!in_single_quotes && !in_double_quotes && c == '#')

Copilot uses AI. Check for mistakes.

FunctionDef* funcDef = nullptr;
if (!eval) {
Error(_W("Evaluator is not initialized."));

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

After checking if eval is null and calling Error(), execution continues to line 61 where eval->getContext() is called. This can cause a null pointer dereference if eval is null. Add an early return after the Error() call on line 59.

Suggested change
Error(_W("Evaluator is not initialized."));
Error(_W("Evaluator is not initialized."));
return retval;

Copilot uses AI. Check for mistakes.
}
Context* context = eval->getContext();
if (!context) {
Error(_W("Context is not initialized."));

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

After checking if context is null and calling Error(), execution continues to line 65 where context->lookupFunction() is called. This can cause a null pointer dereference if context is null. Add an early return after the Error() call on line 63.

Suggested change
Error(_W("Context is not initialized."));
Error(_W("Context is not initialized."));
return retval;

Copilot uses AI. Check for mistakes.
Comment thread modules/os_functions/src/include/cppenv/EnvManager.hpp Dismissed
@Nelson-numerical-software
Nelson-numerical-software merged commit 98cde9f into master Nov 1, 2025
36 checks passed
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.

3 participants