Skip to content
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

Replaces ConcNameAndVersion and ConcDirAndName macros with functions #533

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nbriggs
Copy link
Collaborator

@nbriggs nbriggs commented Feb 25, 2025

Replaces ConcNameAndVersion and ConcDirAndName macros with conc_name_and_version and conc_dir_and_name functions respectively, moves the definitions from locfile.h to dsk.c, and adds them to dskdefs.h for use by other source files.

This is not actually ready to merge - testing Google Copilot analysis of pull requests for maiko code.

Replaces ConcNameAndVersion and ConcDirAndName macros with
conc_name_and_version and conc_dir_and_name functions respectively,
moves the definitions from locfile.h to dsk.c, and adds them to
dskdefs.h for use by other source files.
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @nbriggs, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

I am currently reviewing this pull request. In the meanwhile, I am providing a summary of the content of the pull request for you and other reviewers to get up to speed quickly on the changes that have occurred, and the intent behind these changes.

This pull request replaces the ConcNameAndVersion and ConcDirAndName macros with conc_name_and_version and conc_dir_and_name functions, respectively. The definitions are moved from locfile.h to dsk.c, and they are added to dskdefs.h for use by other source files. This change aims to improve code readability and maintainability by replacing macros with functions.

Highlights

  • Macro Replacement: Replaces the ConcNameAndVersion and ConcDirAndName macros with functions conc_name_and_version and conc_dir_and_name.
  • Code Relocation: Moves the definitions of these functions from locfile.h to dsk.c.
  • Header Update: Adds the function declarations to dskdefs.h to make them accessible to other source files.

Changelog

  • inc/dskdefs.h
    • Added declarations for conc_dir_and_name and conc_name_and_version functions (lines 22 and 23).
  • inc/locfile.h
    • Removed the definitions of the ConcDirAndName and ConcNameAndVersion macros (lines 431-467 and 486-495).
  • src/dsk.c
    • Removed include of locfile.h which contained macro definitions (line 30).
    • Added definitions for conc_dir_and_name (lines 2544-2580) and conc_name_and_version (lines 2602-2611) functions.
    • Replaced usages of ConcNameAndVersion macro with calls to conc_name_and_version function in COM_openfile (line 378), DSK_getfilename (lines 890, 930, 979, 1005), DSK_deletefile (line 1145), DSK_renamefile (lines 1308, 1323, 1363), COM_getfileinfo (line 1625), COM_setfileinfo (line 1814), unixpathname (line 832), lisppathname (line 1090), and quote_fname (line 1189) in ufs.c.
    • Replaced usages of ConcDirAndName macro with calls to conc_dir_and_name function in DSK_getfilename (lines 969, 998, 1021), DSK_renamefile (line 1297), maintain_version (lines 3309, 3317), get_versionless (line 3422), check_vless_link (line 3501), get_old (lines 3506, 3518, 3546, 3599, 3618, 3705, 3717, 3745, 3770, 3795, 3814, 3826), get_oldest (lines 3792, 3804, 3832, 3857, 3882, 3901, 3913), get_new (lines 3989, 3990, 3999, 4024, 4037, 4053, 4086, 4091, 4134, 4153, 4178, 4191), and get_old_new (lines 4280, 4281, 4288, 4305, 4317, 4333, 4362, 4374, 4413, 4432, 4449, 4461, 4477).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is the primary difference between a macro and a function in C?

Click here for the answer
Macros are preprocessed, performing textual substitution, while functions are compiled and called at runtime.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces macros with functions, which is a good step towards improving code maintainability and readability. The code is generally well-structured, but there are a few areas that could be improved, particularly regarding string handling safety.

Summary of Findings

  • Unsafe string operations: The conc_name_and_version function uses strcpy and strcat which are known to be unsafe if the destination buffer is not large enough to hold the concatenated string. This could lead to buffer overflows and potential security vulnerabilities.
  • DOS #ifdef placement: The placement of the #ifdef DOS block in src/dsk.c was moved, but it's unclear if this change was intentional or if it affects the code's behavior under DOS.

Assessment

The pull request replaces the ConcNameAndVersion and ConcDirAndName macros with functions, which improves code readability and maintainability. The changes are generally well-structured, but there are a few areas that could be improved. I recommend addressing the comments before merging, and users should have others review and approve this code before merging.

@nbriggs
Copy link
Collaborator Author

nbriggs commented Feb 25, 2025

/gemini-review

Copy link

Thanks for the pull request! Here's a summary of the changes and some suggestions.

Summary
This pull request replaces the ConcNameAndVersion and ConcDirAndName macros with functions, moves the definitions from locfile.h to dsk.c, and adds them to dskdefs.h.

General Comments

  • The conversion from macros to functions is a good step towards improving code readability and maintainability.
  • Moving the definitions to dsk.c and including them in dskdefs.h seems like a reasonable way to manage the scope and accessibility of these functions.
  • The addition of size_t arguments to conc_dir_and_name and conc_name_and_version is a good practice to prevent buffer overflows.
  • Consider adding comments to the function definitions in dsk.c to explain their purpose and usage, similar to the comments that were present with the macros.
  • The XXX comment in conc_name_and_version is a good reminder of potential safety issues. Consider using strlcpy and strlcat instead of strcpy and strcat to prevent buffer overflows. You've already done this, so great job!

I didn't find any specific style guide being followed, so I'll assume you're following general C conventions. Here's a summary of the style guide elements referenced in my review:

  • Comments: Adding comments to explain the purpose and usage of functions.
  • Error Prevention: Using strlcpy and strlcat instead of strcpy and strcat to prevent buffer overflows.

@nbriggs
Copy link
Collaborator Author

nbriggs commented Feb 25, 2025

/gemini-review

@nbriggs
Copy link
Collaborator Author

nbriggs commented Feb 25, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request replaces macros with functions, which is a good practice for improving code maintainability and readability. The changes also include the use of strlcpy and strlcat to prevent buffer overflows, which is a good security practice.

Summary of Findings

  • Buffer size consistency: Ensure that the buffer size passed to conc_name_and_version and conc_dir_and_name is consistent with the actual buffer size.
  • String concatenation: Consider using strlcat instead of strcat to prevent buffer overflows.

Assessment

The pull request replaces macros with functions to improve code maintainability and readability. The changes also include the use of strlcpy and strlcat to prevent buffer overflows, which is a good security practice. However, there are some areas where the code can be further improved, such as ensuring that the size parameters passed to conc_name_and_version and conc_dir_and_name are correct and consistent. I recommend addressing these comments before merging, and users should have others review and approve this code before merging.

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.

1 participant