Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-3364

Coverity warnings in thread example code

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • WT3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Storage 2017-07-10

      The coverity static analysis tool has reported several warnings in examples/c/ex_thread.c

      Please find the latest report on new defect(s) introduced to WiredTiger found with Coverity Scan.
      
      2 new defect(s) introduced to WiredTiger found with Coverity Scan.
      2 defect(s), reported by Coverity Scan earlier, were marked fixed in the recent build analyzed by Coverity Scan.
      
      New defect(s) Reported-by: Coverity Scan
      Showing 2 of 2 defect(s)
      
      
      ** CID 1375983:  Code maintainability issues  (UNUSED_VALUE)
      /examples/c/ex_thread.c: 109 in main()
      
      
      ________________________________________________________________________________________________________
      *** CID 1375983:  Code maintainability issues  (UNUSED_VALUE)
      /examples/c/ex_thread.c: 109 in main()
      103             cursor->set_key(cursor, "key1");
      104             cursor->set_value(cursor, "value1");
      105             ret = cursor->insert(cursor);
      106             ret = session->close(session, NULL);
      107
      108             for (i = 0; i < NUM_THREADS; i++)
      >>>     CID 1375983:  Code maintainability issues  (UNUSED_VALUE)
      >>>     Assigning value from "__wt_thread_create(NULL, &threads[i], scan_thread, conn)" to "ret" here, but that stored value is overwritten before it can be used.
      109                     ret = __wt_thread_create(NULL, &threads[i], scan_thread, conn);
      110
      111             for (i = 0; i < NUM_THREADS; i++)
      112                     ret = __wt_thread_join(NULL, threads[i]);
      113
      114             ret = conn->close(conn, NULL);
      115
      116             return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
      117     }
      
      ** CID 1375982:  Code maintainability issues  (UNUSED_VALUE)
      /examples/c/ex_thread.c: 112 in main()
      
      
      ________________________________________________________________________________________________________
      *** CID 1375982:  Code maintainability issues  (UNUSED_VALUE)
      /examples/c/ex_thread.c: 112 in main()
      106             ret = session->close(session, NULL);
      107
      108             for (i = 0; i < NUM_THREADS; i++)
      109                     ret = __wt_thread_create(NULL, &threads[i], scan_thread, conn);
      110
      111             for (i = 0; i < NUM_THREADS; i++)
      >>>     CID 1375982:  Code maintainability issues  (UNUSED_VALUE)
      >>>     Assigning value from "__wt_thread_join(NULL, threads[i])" to "ret" here, but that stored value is overwritten before it can be used.
      112                     ret = __wt_thread_join(NULL, threads[i]);
      113
      114             ret = conn->close(conn, NULL);
      115
      116             return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
      117     }
      

      The code is structured the way it is to demonstrate usage without actual error handling, but it should be enhanced to be correct, so that Coverity doesn't issue complaints, and it's more obvious what correct usage is to end users of the example code.

            Assignee:
            keith.bostic@mongodb.com Keith Bostic (Inactive)
            Reporter:
            alexander.gorrod@mongodb.com Alexander Gorrod
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: