Skip to content

Commit e20811a

Browse files
committed
src: os: use Number::New() for CPU info
The return values from uv_cpu_info() don't necessarily fit in a 32 bits signed integer. Fixes nodejs#5732.
1 parent ed80638 commit e20811a

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

src/node_os.cc

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,21 @@ static Handle<Value> GetCPUInfo(const Arguments& args) {
125125
Local<Array> cpus = Array::New();
126126

127127
for (i = 0; i < count; i++) {
128+
uv_cpu_info_t* ci = cpu_infos + i;
129+
128130
Local<Object> times_info = Object::New();
129-
times_info->Set(String::New("user"),
130-
Integer::New(cpu_infos[i].cpu_times.user));
131-
times_info->Set(String::New("nice"),
132-
Integer::New(cpu_infos[i].cpu_times.nice));
133-
times_info->Set(String::New("sys"),
134-
Integer::New(cpu_infos[i].cpu_times.sys));
135-
times_info->Set(String::New("idle"),
136-
Integer::New(cpu_infos[i].cpu_times.idle));
137-
times_info->Set(String::New("irq"),
138-
Integer::New(cpu_infos[i].cpu_times.irq));
131+
times_info->Set(String::New("user"), Number::New(ci->cpu_times.user));
132+
times_info->Set(String::New("nice"), Number::New(ci->cpu_times.nice));
133+
times_info->Set(String::New("sys"), Number::New(ci->cpu_times.sys));
134+
times_info->Set(String::New("idle"), Number::New(ci->cpu_times.idle));
135+
times_info->Set(String::New("irq"), Number::New(ci->cpu_times.irq));
139136

140137
Local<Object> cpu_info = Object::New();
141-
cpu_info->Set(String::New("model"), String::New(cpu_infos[i].model));
142-
cpu_info->Set(String::New("speed"),
143-
Integer::New(cpu_infos[i].speed));
138+
cpu_info->Set(String::New("model"), String::New(ci->model));
139+
cpu_info->Set(String::New("speed"), Number::New(ci->speed));
144140
cpu_info->Set(String::New("times"), times_info);
145-
(*cpus)->Set(i,cpu_info);
141+
142+
(*cpus)->Set(i, cpu_info);
146143
}
147144

148145
uv_free_cpu_info(cpu_infos, count);

0 commit comments

Comments
 (0)