b6d7e4446453c3ab019b30024741247171a2f040
markd
  Mon Jun 29 20:04:40 2020 +0000
make sure data is 64-bit aligned, store offsets in headers to simplify

diff --git src/lib/common.c src/lib/common.c
index 17d09da..86fd419 100644
--- src/lib/common.c
+++ src/lib/common.c
@@ -2621,47 +2621,58 @@
 
 
 void mustRead(FILE *file, void *buf, size_t size)
 /* Read size bytes from a file or squawk and die. */
 {
 if (size != 0 && fread(buf, size, 1, file) != 1)
     {
     if (ferror(file))
 	errAbort("Error reading %lld bytes: %s", (long long)size, strerror(ferror(file)));
     else
 	errAbort("End of file reading %lld bytes", (long long)size);
     }
 }
 
 void writeString(FILE *f, char *s)
-/* Write a 255 or less character string to a file.
- * This will write the length of the string in the first
- * byte then the string itself. */
+/* Write a 255 or less character string to a file.  Truncate if longer.  This
+ * will write the length of the string in the first byte then the string
+ * itself. */
 {
 UBYTE bLen;
 int len = strlen(s);
 
 if (len > 255)
     {
     warn("String too long in writeString (%d chars):\n%s", len, s);
     len = 255;
     }
 bLen = len;
 writeOne(f, bLen);
 mustWrite(f, s, len);
 }
 
+void writeStringSafe(FILE *f, char *s)
+/* Write a 255 or less character string to a file.  Generate an error if
+ * longer.  This will write the length of the string in the first byte then
+ * the string itself. */
+{
+if (strlen(s) > 255)
+    errAbort("attempt to write string longer than 255 bytes");
+writeString(f, s);
+}
+
+
 char *readString(FILE *f)
 /* Read a string (written with writeString) into
  * memory.  freeMem the result when done. */
 {
 UBYTE bLen;
 int len;
 char *s;
 
 if (!readOne(f, bLen))
     return NULL;
 len = bLen;
 s = needMem(len+1);
 if (len > 0)
     mustRead(f, s, len);
 return s;