* limitations under the License.
*/
+#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
{ "ProcCpuUsage", "process cpu" },
};
-#define kBtoKiB(val) (int)(((long long)val * 1024)/1000)
-#define pagetoKiB(val) (int)((long long)val * 4096 / 1000)
+#define MIN(x, y) (x) > (y) ? (x) : (y)
+#define kBtoKiB(val) (int)MIN(((long long)(val) * 1024 / 1000), INT_MAX)
+#define pagetoKiB(val) (int)MIN(((long long)(val) * 4096 / 1000), INT_MAX)
//LCOV_EXCL_START : system error
static int runtime_info_get_dbus_error(const char *err_name)
/* Populate the entries of info array using the data received from resourced */
*info = (process_memory_info_s *)malloc(size * sizeof(process_memory_info_s));
- if (!info) {
+ if (!(*info)) {
_E("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY);
dbus_message_unref(replymsg);
return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
{
FILE *cpuinfo_fp;
char buf[256];
- unsigned long long user, nice, system, idle, iowait, irq, softirq, total_uptime;
+ unsigned long long user = 0;
+ unsigned long long nice = 0;
+ unsigned long long system = 0;
+ unsigned long long idle = 0;
+ unsigned long long iowait = 0;
+ unsigned long long irq = 0;
+ unsigned long long softirq = 0;
+ unsigned long long total_uptime = 0;
if (usage == NULL) {
_E("INVALID_PARAMETER(0x%08x) : invalid output param",
while (fgets(buf, sizeof(buf), cpuinfo_fp) != NULL) {
if (!strncmp(buf, "cpu ", 4) &&
- sscanf(buf+4, "%llu %llu %llu %llu %llu %llu %llu",
+ sscanf(buf + 4, "%llu %llu %llu %llu %llu %llu %llu",
&user, &nice, &system, &idle,
&iowait, &irq, &softirq) == 7)
break;
}
fclose(cpuinfo_fp);
- total_uptime = user+nice+system+idle+iowait+irq+softirq;
+ total_uptime = user + nice + system + idle + iowait + irq + softirq;
- usage->user = (double)user*100/total_uptime;
- usage->nice = (double)nice*100/total_uptime;
- usage->system = (double)system*100/total_uptime;
- usage->iowait = (double)iowait*100/total_uptime;
+ usage->user = (double)user * 100 / total_uptime;
+ usage->nice = (double)nice * 100 / total_uptime;
+ usage->system = (double)system * 100 / total_uptime;
+ usage->iowait = (double)iowait * 100 / total_uptime;
return RUNTIME_INFO_ERROR_NONE;
}