@@ -254,11 +254,31 @@ void Command_Line_Create_Primary_Partition( void )
254254 Shift_Command_Line_Options ( option_count );
255255}
256256
257+ static int Nth_Log_Part_Defined ( Partition_Table * pDrive , int num )
258+ {
259+ int i , valid_parts = 0 ;
260+
261+ for ( i = 0 ; i < MAX_LOGICAL_DRIVES ; i ++ ) {
262+ if ( pDrive -> log_drive [i ].num_type == 0 ) {
263+ continue ;
264+ }
265+
266+ if ( valid_parts == num ) {
267+ return i ;
268+ }
269+
270+ valid_parts ++ ;
271+ }
272+
273+ return i ;
274+ }
275+
257276/* /DELETE command line option */
258277void Command_Line_Delete ( void )
259278{
260279 Partition_Table * pDrive = & part_table [flags .drive_number - 0x80 ];
261280 int error_code = 0 ;
281+ int part_num ;
262282
263283 /* Delete the primary partition */
264284 if ( 0 == strcmp ( arg [1 ].choice , "PRI" ) ) {
@@ -315,8 +335,9 @@ void Command_Line_Delete( void )
315335
316336 /* Delete a Logical DOS Drive */
317337 else if ( 0 == strcmp ( arg [1 ].choice , "LOG" ) ) {
318- if ( ( arg [1 ].value >= 1 ) && ( arg [1 ].value <= 23 ) ) {
319- error_code = Delete_Logical_Drive ( (int )( arg [1 ].value - 1 ) );
338+ if ( ( arg [1 ].value >= 1 ) && ( arg [1 ].value <= MAX_LOGICAL_DRIVES ) &&
339+ ( ( part_num = Nth_Log_Part_Defined ( pDrive , arg [1 ].value - 1 ) ) < MAX_LOGICAL_DRIVES ) ) {
340+ error_code = Delete_Logical_Drive ( part_num );
320341 }
321342 else {
322343 /* NLS:Logical drive number %d is out of range. */
@@ -330,8 +351,9 @@ void Command_Line_Delete( void )
330351 if ( ( arg [1 ].value >= 1 ) && ( arg [1 ].value <= 4 ) ) {
331352 error_code = Delete_Primary_Partition ( (int )( arg [1 ].value - 1 ) );
332353 }
333- else if ( ( arg [1 ].value >= 5 ) && ( arg [1 ].value <= 28 ) ) {
334- error_code = Delete_Logical_Drive ( (int )( arg [1 ].value - 5 ) );
354+ else if ( ( arg [1 ].value >= 5 ) && ( arg [1 ].value <= 28 ) &&
355+ ( ( part_num = Nth_Log_Part_Defined ( pDrive , arg [1 ].value - 5 ) ) < MAX_LOGICAL_DRIVES ) ) {
356+ error_code = Delete_Logical_Drive ( (int )( part_num ) );
335357 }
336358 else {
337359 /* NLS:Partition number is out of range. */
0 commit comments