Processing flags before files in regsvr32
Hugh McMaster
hugh.mcmaster at outlook.com
Tue Jul 14 06:37:52 CDT 2015
After investigating bug 38870 [1], I came up with some possible solutions to this problem.
1. Duplicate argv.
2. Copy the filename argument into a dynamically allocated array.
3. Copy the filename's iteration number (the 'n' of argv[n]) into a dynamically allocated array.
4. Use NULL pointers after processing to determine whether an argument is a flag or a filename.
Of these answers, option four is the lightest and easiest to implement. It is also efficient.
The idea is to assign argv[i] = NULL after we have processed an argument that is a flag.
So, I'm proposing something like this pseudo-code (there is an actual diff below):
for (i = 1; i < argc; i++)
{
if (is a flag)
{
do something;
argv[i] = NULL;
}
}
for (i = 1; i < argc; i++)
{
if (argv[i]) /* only filenames are valid */
do something;
}
diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c
index 449124f..ef895e0 100644
--- a/programs/regsvr32/regsvr32.c
+++ b/programs/regsvr32/regsvr32.c
@@ -270,8 +270,13 @@ int wmain(int argc, WCHAR* argv[])
output_write(STRING_USAGE);
return 1;
}
+ argv[i] = NULL;
}
- else
+ }
+
+ for (i = 1; i < argc; i++)
+ {
+ if (argv[i])
{
WCHAR *DllName = argv[i];
int res = 0;
The proposed changes work correctly, both with a test DLL and also MediaInfo program from the bug.
Any comments and suggestions are welcome.
[1] https://bugs.winehq.org/show_bug.cgi?id=38870
More information about the wine-devel
mailing list