Commit Graph
204 Commits
Author SHA1 Message Date
Pierre Gondoisandmergify[bot] 12e26dc213 ShellPkg/TimeDate: Extract GetTimeZoneFromString() helper
Extract a GetTimeZoneFromString() function to decrease the
size of MainCmdTime().

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] c062ff8487 ShellPkg/TimeDate: Extract PrintDaylight() helper
Extract a PrintDaylight() function to decrease the
size of MainCmdTime().

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] a366d6f8fe ShellPkg/TimeDate: Extract PrintTime() helper
Extract a PrintTime() function to factorize the code.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 0f69afa295 ShellPkg/TimeDate: Extract GetCurrentTime() helper
Extract a GetCurrentTime() function to factorize error
messages.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] be6ce32cd0 ShellPkg/Ls: Extract PrintLsOutputCurr() function
Extract a PrintLsOutputCurr() function to decrease
the size of PrintLsOutput().

The patch also rationalize the usage of the Found
parameter:
- Found is updated only when a valid MetaFile is found
- a IsRecursive variable is created to distinguish
  the first PrintLsOutput() call from the other
  recursive ones.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 636761d3ca ShellPkg/Ls: Lower PrintLsOutputRec() indentation level
Invert some conditions in PrintLsOutputRec() to lower
the indentation level.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] da54ab306a ShellPkg/Ls: Extract PrintLsOutputRec() function
Extract a PrintLsOutputRec() function to decrease
the size of PrintLsOutput().

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 08bc059570 ShellPkg/Ls: Remove unused TimeZone parameter
The TimeZone parameter is not used. Remove it.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 78b550f43d ShellPkg/Ls: Hard-code number of files if none found
If no file/directory has been found, the number of
files/directories must be 0.
Hard-code these values to avoid depending on the
FileCount/FileSize/DirCount variables.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 273edd9e01 ShellPkg/Ls: Extract GetCorrectedPath() function
Extract a GetCorrectedPath() function to decrease
the size of PrintLsOutput().

Also free the CorrectedPath in PrintLsOutput() before
re-allocating it to prepare for follow-up factorization.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 9171edd4d4 ShellPkg/Ls: Move FileMetaArg closing logic
Move ShellCloseFileMetaArg() calls to close the
MetaArg whenever its usage is not needed anymore.
This prepares for follow-up factorization.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] c45e930ad5 ShellPkg/Ls: Extract UpdateFileLocalTime() function
Extract a UpdateFileLocalTime() function to decrease
the size of PrintLsOutput().

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 6829285f88 ShellPkg/Rm: Extract DeleteDirectory() function
Extract a DeleteDirectory() function to decrease
the size of CascadeDelete().

The extracted logic is slighly modified to lower
the indendation level.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Pierre Gondoisandmergify[bot] 420dab0b24 ShellPkg/UefiShellLib: Add IsDotOrDotDot() function
Replace existing checks against L"." and L".." by
a named function.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2026-04-24 18:18:47 +00:00
Michael Kubackiandmergify[bot] 8472271dae ShellPkg: Replace include guards with #pragma once
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.

`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.

Compared to macro-based include guards, `#pragma once`:

- Eliminates the risk of macro name collisions or copy/paste errors
  where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
  (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
  file entirely, rather than re-reading it to find the matching
  `#endif` ("multiple-include optimization").
  - Note that some compilers may already optimize traditional include
    guards, by recognzining the idiomatic pattern.

This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.

However, this is considered acceptable given:

1. edk2 already defines a subset of supported compilers in
   BaseTools/Conf/tools_def.template, all of which have supported
   `#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
   include guard naming and potential macro collisions.

Approximate compiler support dates:

- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
  (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-23 21:01:28 +00:00
Mingjie Shenandmergify[bot] ee0084a071 ShellPkg/Mv: Harden and optimize trailing-slash trimming
- Remove redundant null check in IsValidMove() per CodeQL
  cpp/redundant-null-check-simple. Specifically, drop the
  "DestPathWalker != NULL" condition from the trimming loop.
  Rationale: "DestPathCopy" is allocated at line 181 and checked for
  NULL at lines 182–183; "DestPathWalker" is initialized from
  "DestPathCopy" at line 186, so it cannot be NULL.
- Cache length once in IsValidMove() and ValidateAndMoveFiles() so the
  trimming loop avoids repeated StrLen() calls.
- Guard the zero-length case before indexing the last character to
  prevent out-of-bounds access.

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2025-12-03 17:41:35 +00:00
Pierre GondoisandArd Biesheuvel 19c62fd3ac ShellPkg/UefiShellLevel2: Fix CodeQl issues
Fix CodeQl issue triggered by the previous patches.
- Rm: FileList might be NULL

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-12-02 09:00:53 +01:00
Pierre GondoisandArd Biesheuvel 95476665c4 ShellPkg/UefiShellLevel2/Ls: Remove ShellStatus check in MainCmdLs()
Remove a check against ShellStatus in MainCmdLs() as there are
two consecutive checks without any modification of ShellStatus.

Suggested-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-12-02 09:00:53 +01:00
Pierre GondoisandArd Biesheuvel 8e822d5d26 ShellPkg/UefiShellLevel2/Ls: Bail out early in MainCmdLs()
If RootPath is NULL, PrintLsOutput() will return an error code
of SHELL_OUT_OF_RESOURCES and not print anything:
PrintLsOutput()
\-StrnCatGrow()
  if (Source == NULL) {
    return (*Destination);
  }

Remove paths where FullPath ends up being NULL and bail out
early.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-12-02 09:00:53 +01:00
Pierre GondoisandArd Biesheuvel 0b982813c7 ShellPkg/UefiShellLevel2/Ls: Flatten MainCmdLs()
Remove some of the success handling conditions to flatten
the MainCmdLs() function.

No functional change should be induced by this patch.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-12-02 09:00:53 +01:00
Pierre GondoisandArd Biesheuvel 5b1530e5ad ShellPkg/UefiShellLevel2: Lower indentation level in MainCmdXXX()
This patch aims to help breaking down the long function present in
the ShellPkg and reduce complexity/nested code and conditions.

Lower the indentation level in the newly created MainCmdXXX()
functions.

No functional change should be induced by this patch.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-12-02 09:00:53 +01:00
Pierre GondoisandArd Biesheuvel 531b0aa002 ShellPkg/UefiShellLevel2: Extract MainCmdXXX() function
This patch aims to help breaking down the long function present in
the ShellPkg and reduce complexity/nested code and conditions.

Extract a MainCmdXXX() function for each shell command.
This command contains the possible operations the command aims
to operate. The ShellCommandRunXXX() function from which it
is extracted is only responsible of:
- initializing the shell/command environment
- parsing the command parameter and creating a Package
- freeing the Package

No functional change should be induced by this patch.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-12-02 09:00:53 +01:00
Pierre GondoisandArd Biesheuvel ce88903374 ShellPkg/UefiShellLevel2: Return if ShellCommandLineParse() failed
This patch aims to help breaking down the long function present in
the ShellPkg and reduce complexity/nested code and conditions.

Return directly if ShellCommandLineParse() returned an error Status.
In such case, the "Package" that should be allocated by
ShellCommandLineParse() is already freed in:
ShellCommandLineParse()
\-ShellCommandLineParseEx()
  \-InternalCommandLineParse()
so there is no need to free it with ShellCommandLineFreeVarList().

Note:
Cd:
Return directly if ShellCommandLineParse() returned an error
Status. The initial code was ignoring the error status.

Cp:
Only check for ShellGetExecutionBreakFlag() if
ShellCommandLineParse() returned successfully. If the command
line failed to be parsed, there should be no need to check for
the execution break flag.

No functional change should be induced by this patch.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-12-02 09:00:53 +01:00
Leif Lindholmandpierregondois 8b22c532b3 ShellPkg/Library: rework Shell...CommandsLib Load.c
CodeQL incorrectly flags that LoadedDriverImage might be derferenced
while NULL, but the actual code paths make that impossible.

Strip several levels of success handling to improve readability for
humans and static analyzers both.

Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
2025-10-01 10:02:57 +02:00
Pierre Gondoisandpierregondois aa29d51637 ShellPkg: Use the newly introduced ShellPrintDefaultEx() alias
Make use the newly introduced ShellPrintDefaultEx() alias and
replace wherever it is possible:
- "ShellPrintEx (-1, -1,"
with:
- "ShellPrintDefaultEx ("

No functional change is introduced.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-10-01 10:02:57 +02:00