@@ -153,22 +153,35 @@ func DecomposeCommandLine(commandLine string) ([]string, error) {
153
153
return nil , errorspkg .New ("string with NUL passed to DecomposeCommandLine" )
154
154
}
155
155
var argc int32
156
- argv8192 , err := CommandLineToArgv (& utf16CommandLine [0 ], & argc )
156
+ argv , err := commandLineToArgv (& utf16CommandLine [0 ], & argc )
157
157
if err != nil {
158
158
return nil , err
159
159
}
160
- defer LocalFree (Handle (unsafe .Pointer (argv8192 )))
160
+ defer LocalFree (Handle (unsafe .Pointer (argv )))
161
161
162
162
var args []string
163
- // Note: CommandLineToArgv hard-codes an incorrect return type
164
- // (see https://go.dev/issue/63236).
165
- // We use an unsafe.Pointer conversion here to work around it.
166
- for _ , p := range unsafe .Slice ((* * uint16 )(unsafe .Pointer (argv8192 )), argc ) {
163
+ for _ , p := range unsafe .Slice (argv , argc ) {
167
164
args = append (args , UTF16PtrToString (p ))
168
165
}
169
166
return args , nil
170
167
}
171
168
169
+ // CommandLineToArgv parses a Unicode command line string and sets
170
+ // argc to the number of parsed arguments.
171
+ //
172
+ // The returned memory should be freed using a single call to LocalFree.
173
+ //
174
+ // Note that although the return type of CommandLineToArgv indicates 8192
175
+ // entries of up to 8192 characters each, the actual count of parsed arguments
176
+ // may exceed 8192, and the documentation for CommandLineToArgvW does not mention
177
+ // any bound on the lengths of the individual argument strings.
178
+ // (See https://go.dev/issue/63236.)
179
+ func CommandLineToArgv (cmd * uint16 , argc * int32 ) (argv * [8192 ]* [8192 ]uint16 , err error ) {
180
+ argp , err := commandLineToArgv (cmd , argc )
181
+ argv = (* [8192 ]* [8192 ]uint16 )(unsafe .Pointer (argp ))
182
+ return argv , err
183
+ }
184
+
172
185
func CloseOnExec (fd Handle ) {
173
186
SetHandleInformation (Handle (fd ), HANDLE_FLAG_INHERIT , 0 )
174
187
}
0 commit comments