summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2005-10-13 14:54:23 +0000
committerSascha Hauer <s.hauer@pengutronix.de>2005-10-13 14:54:23 +0000
commitca389c506f22dfec40da56ad84c78f836782485b (patch)
treed1e63f15e0ec0e5a690f2149dcc9864f26aa0a25
parent2db64a22201070842316e61057ebf6a279a0d22d (diff)
downloadmemedit-ca389c506f22dfec40da56ad84c78f836782485b.tar.gz
memedit-ca389c506f22dfec40da56ad84c78f836782485b.tar.xz
make arguments to hex_output unsigned, add some sanity checks
-rw-r--r--memedit.y27
1 files changed, 17 insertions, 10 deletions
diff --git a/memedit.y b/memedit.y
index e9a963a..fd52d63 100644
--- a/memedit.y
+++ b/memedit.y
@@ -24,8 +24,8 @@ typedef struct variable {
int val;
} variable;
-long map_ofs = 0;
-long map_size = 0;
+unsigned long map_ofs = 0;
+unsigned long map_size = 0;
int in_line = 0;
#define LINELEN 16
@@ -34,7 +34,7 @@ variable *vlist;
void set_variable (char *param, int val);
int get_variable (char *param);
-int hex_output (int offset, int len, int count);
+int hex_output (unsigned long offset, unsigned long len, unsigned long count);
void print_help (void);
extern void yyerror (const char *s);
@@ -324,9 +324,8 @@ int get_variable (char *param) {
return v;
}
-int hex_output (int offset, int len, int count) {
- unsigned int c;
- int j, t, bytes;
+int hex_output (unsigned long offset, unsigned long len, unsigned long count) {
+ unsigned long c, j, t, bytes;
unsigned char linebuf[LINELEN];
if (fd<0) {
@@ -334,6 +333,14 @@ int hex_output (int offset, int len, int count) {
return 0;
}
+ if( offset > map_size ) {
+ printf("region not mapped\n");
+ return -1;
+ }
+
+ if( offset + count > map_size )
+ count = map_size - offset;
+
while(1) {
unsigned char *linechar = (unsigned char *)linebuf;
unsigned int *lineint = (unsigned int *)linebuf;
@@ -343,7 +350,7 @@ int hex_output (int offset, int len, int count) {
volatile unsigned short *rbuff16 = mem + offset;
volatile unsigned char *rbuff8 = mem + offset;
- printf ("%08x: ", offset);
+ printf ("%08lx: ", offset);
bytes = LINELEN > count ? count : LINELEN;
if( bytes + offset > map_size )
bytes = map_size - offset;
@@ -352,17 +359,17 @@ int hex_output (int offset, int len, int count) {
switch (len) {
case 1:
c = *rbuff8++;
- printf ("%02x ", c);
+ printf ("%02lx ", c);
*linechar++ = c;
break;
case 2:
c = *rbuff16++;
- printf ("%04x ", c);
+ printf ("%04lx ", c);
*lineshort++ = c;
break;
case 4:
c = *rbuff32++;
- printf ("%08x ", c);
+ printf ("%08lx ", c);
*lineint++ = c;
break;
}