Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
-A option processing in fdisk(8)
Currently, fdisk uses the following code to parse the -A option:
case 'A': /* Partition alignment[/offset] */
if (sscanf(optarg, "%u/%u%n", &ptn_alignment,
&ptn_0_offset, &n) < 1
|| optarg[n] != 0
|| ptn_0_offset > ptn_alignment)
errx(1, "Bad argument to the -A flag.");
if (ptn_0_offset == 0)
ptn_0_offset = ptn_alignment;
break;
This doesn't seem right, and in actual practice using '-A 2048' results
in the "Bad argument" error message. I think this is because &n is
still set to zero since the scan never gets that far.
It seems to me that this should be rewritten as
case 'A': /* Partition alignment[/offset] */
ptn_0_offset = 0;
if (sscanf(optarg, "%u%n/%u%n", &ptn_alignment,
&n, &ptn_0_offset, &n) < 1
|| optarg[n] != 0
|| ptn_0_offset > ptn_alignment)
errx(1, "Bad argument to the -A flag.");
if (ptn_0_offset == 0)
ptn_0_offset = ptn_alignment;
break;
This would cause &n to be set as soon as the first numeric value was
sscanf'd, whether or not it is followed by a '/%u'.
Comments?
-------------------------------------------------------------------------
| Paul Goyette | PGP Key fingerprint: | E-mail addresses: |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer | | pgoyette at netbsd.org |
-------------------------------------------------------------------------
Home |
Main Index |
Thread Index |
Old Index