- size_t len = strlen(string) + 1;
-
- if (len == 1 && next_free != 0) {
- /*
- * Cheat a little by making an empty string point to the end of the
- * previous string.
- */
- if (next_free < MAX_STRTAB) {
- result = (stringbuf + next_free - 1);
+ size_t len;
+
+ if (stringbuf != NULL) {
+ if (!VALID_STRING(string))
+ string = "";
+ len = strlen(string) + 1;
+
+ if (len == 1 && next_free != 0) {
+ /*
+ * Cheat a little by making an empty string point to the end of the
+ * previous string.
+ */
+ if (next_free < MAX_ENTRY_SIZE) {
+ result = (stringbuf + next_free - 1);
+ }
+ } else if (next_free + len < MAX_ENTRY_SIZE) {
+ _nc_STRCPY(&stringbuf[next_free], string, MAX_ENTRY_SIZE);
+ DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
+ DEBUG(7, ("at location %d", (int) next_free));
+ next_free += len;
+ result = (stringbuf + old_next_free);
+ } else {
+ _nc_warning("Too much data, some is lost: %s", string);