]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/room_ops.c
CtdlFetchMsgList() - treat no-record and zero-messages identically
[citadel.git] / citadel / server / room_ops.c
index 5eb5e69fa67b91b86b23358f4d83100d78feec0f..749bcacb9130dbe8db1da339eade82c2cdd24787 100644 (file)
@@ -604,7 +604,7 @@ int CtdlIsNonEditable(struct ctdlroom *qrbuf) {
 // Retrieve a list of all messages (message numbers) in the specified room.
 // Returns the number of messages in the room, allocates a pointer to the array and stuffs it in the supplied location.
 // Caller must free that memory.
-// Returns (-1) if error.
+// If no messages in room, returns 0 and msgs is set to NULL.
 int CtdlFetchMsgList(long roomnum, long **msgs) {
        int num_msgs = 0;
         struct cdbdata *cdbfr;
@@ -613,12 +613,17 @@ int CtdlFetchMsgList(long roomnum, long **msgs) {
        if (cdbfr == NULL) {
                syslog(LOG_ERR, "room_ops: no msglist for room %ld", roomnum);
                *msgs = NULL;
-               return (-1);
+               return (0);
        }
 
-       *msgs = malloc(cdbfr->len);
-       memcpy(*msgs, cdbfr->ptr, cdbfr->len);
                num_msgs = cdbfr->len / sizeof(long);
+       if (num_msgs > 0) {
+               *msgs = malloc(cdbfr->len);
+               memcpy(*msgs, cdbfr->ptr, cdbfr->len);
+       }
+       else {
+               *msgs = NULL;
+       }
                cdb_free(cdbfr);
        // BEGIN diagnostic section remove this
        syslog(LOG_DEBUG, "\033[7mCtdlFetchMsgList(%ld) %d messages\033[0m", roomnum, num_msgs);