Re: [PATCH] Implement an offset option for vbladed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ed Cashin wrote...

> ... but noticed along the way that you're using atoi.  Because
> you're supporting 64-bit numbers, would you mind sending a patch
> that uses strtoll or doing it in git and sending a pull request?

So, version 3 then. I have some issues with github so let's better
stay on patches, at least as long the changes are that small. This is
based on commit baa96be.

You suggested strtoll - mostly because it's appearently more portable
then atoll I guess? These strto* functions could also be used to add
error checking, something that isn't done yet for shelf and slot
either. I could add that everywhere if you wish but that should be
kept for a second round then.

Another addition: Both length and offset might have negative values,
check that. And use signed format strings.

    Christoph

diff --git a/aoe.c b/aoe.c
index ef590ae..6f51a4b 100644
--- a/aoe.c
+++ b/aoe.c
@@ -488,10 +488,10 @@ main(int argc, char **argv)
 			setmask(optarg);
 			break;
 		case 'o':
-			offset = atoi(optarg);
+			offset = strtoll(optarg, NULL, 10);
 			break;
 		case 'l':
-			length = atoi(optarg);
+			length = strtoll(optarg, NULL, 10);
 			break;
 		case '?':
 		default:
@@ -513,14 +513,22 @@ main(int argc, char **argv)
 	setserial(argv[3], shelf, slot);
 	size = getsize(bfd);
 	size /= 512;
+	if (offset < 0) {
+		fprintf(stderr, "Offset %lli is negative\n", offset);
+		exit(1);
+	}
 	if (size < offset) {
-		fprintf(stderr, "Offset %llu too big - remaining size is negative!\n", offset);
+		fprintf(stderr, "Offset %lli too big - remaining size is negative!\n", offset);
 		exit(1);
 	}
 	size -= offset;
+	if (length < 0) {
+		fprintf(stderr, "Length %lli is negative\n", length);
+		exit(1);
+	}
 	if (length) {
 		if (length > size) {
-			fprintf(stderr, "Length %llu too big - exceeds size of file!\n", offset);
+			fprintf(stderr, "Length %lli too big - exceeds size of file!\n", offset);
 			exit(1);
 		}
 		size = length;

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Aoetools-discuss mailing list
Aoetools-discuss@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/aoetools-discuss




[Index of Archives]     [Linux ARM Kernel]     [Linux SCSI]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux