<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -57,7 +57,7 @@ int daemon(int nochdir, int noclose)
     if (nochdir == 0)
         (void)chdir(&quot;/&quot;);
 
-    if (noclose==0 &amp;&amp; (fd = open(&quot;/dev/null&quot;, O_RDWR, 0)) != -1) {
+    if (noclose == 0 &amp;&amp; (fd = open(&quot;/dev/null&quot;, O_RDWR, 0)) != -1) {
         (void)dup2(fd, STDIN_FILENO);
         (void)dup2(fd, STDOUT_FILENO);
         (void)dup2(fd, STDERR_FILENO);</diff>
      <filename>daemon.c</filename>
    </modified>
    <modified>
      <diff>@@ -283,7 +283,7 @@ char *item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, u
     bufcurr = 0;
 
     while (it != NULL &amp;&amp; (limit == 0 || shown &lt; limit)) {
-        len = snprintf(temp, 512, &quot;ITEM %s [%d b; %lu s]\r\n&quot;, ITEM_key(it), it-&gt;nbytes - 2, it-&gt;time + stats.started);
+        len = snprintf(temp, sizeof(temp), &quot;ITEM %s [%d b; %lu s]\r\n&quot;, ITEM_key(it), it-&gt;nbytes - 2, it-&gt;time + stats.started);
         if (bufcurr + len + 6 &gt; memlimit)  /* 6 is END\r\n\0 */
             break;
         strcpy(buffer + bufcurr, temp);
@@ -301,7 +301,9 @@ char *item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, u
 
 void item_stats(char *buffer, const int buflen) {
     int i;
+    int linelen;
     char *bufcurr = buffer;
+    size_t bufleft = (size_t) buflen;
     rel_time_t now = current_time;
 
     if (buflen &lt; 4096) {
@@ -310,9 +312,18 @@ void item_stats(char *buffer, const int buflen) {
     }
 
     for (i = 0; i &lt; LARGEST_ID; i++) {
-        if (tails[i] != NULL)
-            bufcurr += snprintf(bufcurr, (size_t)buflen, &quot;STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n&quot;,
+        if (tails[i] != NULL) {
+            linelen = snprintf(bufcurr, bufleft, &quot;STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n&quot;,
                                i, sizes[i], i, now - tails[i]-&gt;time);
+            if (linelen + sizeof(&quot;END&quot;) &lt; bufleft) {
+                bufcurr += linelen;
+                bufleft -= linelen;
+            }
+            else {
+                /* The caller didn't allocate enough buffer space. */
+                break;
+            }
+        }
     }
     memcpy(bufcurr, &quot;END&quot;, 4);
     return;</diff>
      <filename>items.c</filename>
    </modified>
    <modified>
      <diff>@@ -246,7 +246,7 @@ static int freecurr;
 static void conn_init(void) {
     freetotal = 200;
     freecurr = 0;
-    if (!(freeconns = (conn **)malloc(sizeof(conn *) * freetotal))) {
+    if ((freeconns = (conn **)malloc(sizeof(conn *) * freetotal)) == NULL) {
         perror(&quot;malloc()&quot;);
     }
     return;
@@ -936,7 +936,7 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
         int fd;
         int res;
 
-        if (!(wbuf = (char *)malloc(wsize))) {
+        if ((wbuf = (char *)malloc(wsize)) == NULL) {
             out_string(c, &quot;SERVER_ERROR out of memory&quot;);
             return;
         }
@@ -2430,7 +2430,7 @@ static void save_pid(const pid_t pid, const char *pid_file) {
     if (pid_file == NULL)
         return;
 
-    if (!(fp = fopen(pid_file, &quot;w&quot;))) {
+    if ((fp = fopen(pid_file, &quot;w&quot;)) == NULL) {
         fprintf(stderr, &quot;Could not open the pid file %s for writing\n&quot;, pid_file);
         return;
     }
@@ -2733,7 +2733,10 @@ int main (int argc, char **argv) {
     /* initialise deletion array and timer event */
     deltotal = 200;
     delcurr = 0;
-    todelete = malloc(sizeof(item *) * deltotal);
+    if ((todelete = malloc(sizeof(item *) * deltotal)) == NULL) {
+        perror(&quot;failed to allocate memory for deletion array&quot;);
+        exit(EXIT_FAILURE);
+    }
     delete_handler(0, 0, 0); /* sets up the event */
     /* create the initial listening udp connection, monitored on all threads */
     if (u_socket &gt; -1) {</diff>
      <filename>memcached.c</filename>
    </modified>
    <modified>
      <diff>@@ -310,7 +310,7 @@ static void thread_libevent_process(int fd, short which, void *arg) {
     if (NULL != item) {
         conn *c = conn_new(item-&gt;sfd, item-&gt;init_state, item-&gt;event_flags,
                            item-&gt;read_buffer_size, item-&gt;is_udp, me-&gt;base);
-        if (!c) {
+        if (c == NULL) {
             if (item-&gt;is_udp) {
                 fprintf(stderr, &quot;Can't listen for events on UDP socket\n&quot;);
                 exit(1);</diff>
      <filename>thread.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cdcf9f8d9c83c2d3df23e4f5dd85e341b7139c6a</id>
    </parent>
  </parents>
  <author>
    <name>sgrimm</name>
    <email>sgrimm@b0b603af-a30f-0410-a34e-baf09ae79d0b</email>
  </author>
  <url>http://github.com/tmaesaka/memcached/commit/129e3610e6f1a7eff02e6a7be7b6e0dd36c2e7fa</url>
  <id>129e3610e6f1a7eff02e6a7be7b6e0dd36c2e7fa</id>
  <committed-date>2007-07-07T17:01:52-07:00</committed-date>
  <authored-date>2007-07-07T17:01:52-07:00</authored-date>
  <message>Fix minor style inconsistencies and add some missing error checking.


git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@587 b0b603af-a30f-0410-a34e-baf09ae79d0b</message>
  <tree>7036eb47ba71f23aca6438b3e699d8cadd3fa37c</tree>
  <committer>
    <name>sgrimm</name>
    <email>sgrimm@b0b603af-a30f-0410-a34e-baf09ae79d0b</email>
  </committer>
</commit>
