On Feb 12, 2008 9:04 PM, ron minnich <[EMAIL PROTECTED]> wrote:
> how about taking it away from explicit bit widths? Unless the bit
> width of a type absolutely needs to be set, you ought to use an int or
> even unsigned int. Can you try it?
>
> ron
>

Because the code uses int a lot more than unsigned int, I used int.
There are still many places where your rule is not followed, but this
works and moves in that direction.

nrv2b.c in particular could use some help.  It doesn't compile if safe
is defined, because of undefined variables.  The input parameter len
is never used either.  I think that should be a separate patch.

Myles

Signed-off-by: Myles Watson <[EMAIL PROTECTED]>
Index: util/lzma/minilzma.cc
===================================================================
--- util/lzma/minilzma.cc	(revision 587)
+++ util/lzma/minilzma.cc	(working copy)
@@ -280,15 +280,15 @@
 #else
 extern "C" {
 
-void do_lzma_compress(char *in, unsigned long in_len, char *out,
-		      unsigned long *out_len) {
+void do_lzma_compress(char *in, int in_len, char *out,
+		      int *out_len) {
 	std::vector<unsigned char> result;
 	result = LZMACompress(std::vector<unsigned char>(in, in + in_len));
 	*out_len = result.size();
 	std::memcpy(out, &result[0], *out_len);
 }
 
-void do_lzma_uncompress(char *dst, char *src, unsigned long len) {
+void do_lzma_uncompress(char *dst, char *src, int len) {
 	std::vector<unsigned char> result;
 	result = LZMADeCompress(std::vector<unsigned char>(src, src + len));
 	std::memcpy(dst, &result[0], result.size());
Index: util/nrv2b/nrv2b.c
===================================================================
--- util/nrv2b/nrv2b.c	(revision 587)
+++ util/nrv2b/nrv2b.c	(working copy)
@@ -1304,10 +1304,11 @@
 #endif
 
 #ifdef COMPACT
-void do_nrv2b_compress(uint8_t *in, unsigned long in_len, uint8_t *out, unsigned long *out_len) {
-	*out_len = in_len + (in_len/8) + 256;
-	out = malloc(*out_len);
-	ucl_nrv2b_99_compress(in, in_len, out, out_len, 0 );
+void do_nrv2b_compress(uint8_t *in, int in_len, uint8_t *out, int *out_len) {
+	unsigned long new_out_len = in_len + (in_len/8) + 256;
+	out = malloc(new_out_len);
+	ucl_nrv2b_99_compress(in, in_len, out, &new_out_len, 0 );
+	*out_len = (int) new_out_len;
 }
 #endif
 
@@ -1346,7 +1347,7 @@
 #endif
 
 #ifdef COMPACT
-void do_nrv2b_uncompress(uint8_t *dst, uint8_t *src, unsigned long len) {
+void do_nrv2b_uncompress(uint8_t *dst, uint8_t *src, int len) {
 	unsigned long ilen = 0, olen = 0, last_m_off = 1;
 	uint32_t bb = 0;
 	unsigned bc = 0;
Index: util/lar/lar.h
===================================================================
--- util/lar/lar.h	(revision 588)
+++ util/lar/lar.h	(working copy)
@@ -93,18 +93,18 @@
 
 enum compalgo { none = 0, lzma = 1, nrv2b = 2 };
 
-typedef void (*compress_func) (char *, u32, char *, u32 *);
-typedef void (*uncompress_func) (char *, char *, u32);
+typedef void (*compress_func) (char *, int, char *, int *);
+typedef void (*uncompress_func) (char *, char *, int);
 
-void compress_impossible(char *in, u32 in_len, char *out, u32 *out_len);
-void do_no_compress(char *in, u32 in_len, char *out, u32 *out_len);
-void do_lzma_compress(char *in, u32 in_len, char *out, u32 *out_len);
-void do_nrv2b_compress(char *in, u32 in_len, char *out, u32 *out_len);
+void compress_impossible(char *in, int in_len, char *out, int *out_len);
+void do_no_compress(char *in, int in_len, char *out, int *out_len);
+void do_lzma_compress(char *in, int in_len, char *out, int *out_len);
+void do_nrv2b_compress(char *in, int in_len, char *out, int *out_len);
 
-void uncompress_impossible(char *, char *, u32);
-void do_no_uncompress(char *, char *, u32);
-void do_lzma_uncompress(char *, char *, u32);
-void do_nrv2b_uncompress(char *, char *, u32);
+void uncompress_impossible(char *, char *, int);
+void do_no_uncompress(char *, char *, int);
+void do_lzma_uncompress(char *, char *, int);
+void do_nrv2b_uncompress(char *, char *, int);
 
 static compress_func compress_functions[] = {
 	do_no_compress,
Index: util/lar/lib.c
===================================================================
--- util/lar/lib.c	(revision 588)
+++ util/lar/lib.c	(working copy)
@@ -40,7 +40,7 @@
  * The default "compress impossible" hook to call when no other compression
  * is used
  */
-void compress_impossible(char *in, u32 in_len, char *out, u32 *out_len)
+void compress_impossible(char *in, int in_len, char *out, int *out_len)
 {
 	fprintf(stderr,
 		"The selected compression algorithm wasn't compiled in.\n");
@@ -50,7 +50,7 @@
 /**
  * The default "compress" hook to call when no other compression is used
  */
-void do_no_compress(char *in, u32 in_len, char *out, u32 *out_len)
+void do_no_compress(char *in, int in_len, char *out, int *out_len)
 {
 	memcpy(out, in, in_len);
 	out_len[0] = in_len;
@@ -60,7 +60,7 @@
  * The default "uncompress" hook to call when no other compression is used
  */
 
-void do_no_uncompress(char *dst, char *src, u32 len)
+void do_no_uncompress(char *dst, char *src, int len)
 {
 	memcpy(dst, src, len);
 }
@@ -68,7 +68,7 @@
 /**
  * The default "uncompress" hook to call when no other compression is used
  */
-void uncompress_impossible(char *dst, char *src, u32 len)
+void uncompress_impossible(char *dst, char *src, int len)
 {
 	fprintf(stderr,
 		"Cannot uncompress data (algorithm not compiled in).\n");
Index: util/lar/lib.h
===================================================================
--- util/lar/lib.h	(revision 588)
+++ util/lar/lib.h	(working copy)
@@ -58,7 +58,7 @@
 /* Prototypes for in-memory LAR operations */
 int lar_process_name(char *name, char **pfilename, char **ppathname, 
 		enum compalgo *thisalgo);
-u32 lar_compress(char *ptr, ssize_t size, char *temp, enum compalgo *thisalgo);
+int lar_compress(char *ptr, int size, char *temp, enum compalgo *thisalgo);
 int hlen(char *name);
 int maxsize(struct lar *lar, char *name);
 int lar_add_entry(struct lar *lar, char *pathname, void *data, 
Index: util/lar/stream.c
===================================================================
--- util/lar/stream.c	(revision 588)
+++ util/lar/stream.c	(working copy)
@@ -113,7 +113,7 @@
 		ehdr->e_type,
 		ehdr->e_machine,
 		ehdr->e_version,
-		(void *)ehdr->e_entry,
+		(void *)(unsigned long)ehdr->e_entry,
 		ehdr->e_phoff,
 		ehdr->e_shoff,
 		ehdr->e_flags,
@@ -155,7 +155,7 @@
 		size = shdr[i].sh_size;
 		if (verbose()) {
 			fprintf(stderr, "(cleaned up) New section addr %p size 0x%#x\n",
-				(void *)shdr[i].sh_addr, (u32)shdr[i].sh_size);
+				(void *)(unsigned long)shdr[i].sh_addr, (u32)shdr[i].sh_size);
 		}
 			/* ok, copy it out */
 		sprintf(ename, "%s/segment%d", name, segment++);
@@ -193,9 +193,9 @@
 		}
 		if (verbose()) {
 			fprintf(stderr, "(cleaned up) New segment addr %p size 0x%#x offset 0x%x\n",
-				(void *)phdr[i].p_paddr, size, phdr[i].p_offset);
+				(void *)(unsigned long)phdr[i].p_paddr, size, phdr[i].p_offset);
 			fprintf(stderr, "Copy to %p from %p for %d bytes\n", 
-				(unsigned char *)phdr[i].p_paddr, 
+				(unsigned char *)(unsigned long)phdr[i].p_paddr, 
 				&header[phdr[i].p_offset], size);
 			fprintf(stderr, "entry %ux loadaddr %ux\n", 
 				entry,  phdr[i].p_paddr);
@@ -840,9 +840,9 @@
  * @param thisalgo pointer to algorithm -- this can be modified
  * @return  size of compressed data
  */
-u32 lar_compress(char *ptr, ssize_t size, char *temp, enum compalgo *thisalgo)
+int lar_compress(char *ptr, int size, char *temp, enum compalgo *thisalgo)
 {
-	u32 complen;
+	int complen;
 	compress_functions[*thisalgo](ptr, size, temp, &complen);
 
 	if (complen >= size && (*thisalgo != none)) {
-- 
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to