ref: fc77a2d3d384c1ee854deebd4f1a97e751d7eaa2
parent: d5d6724805fa7df9cb74d9b05a4eb3bf10d1997c
author: cinap_lenrek <[email protected]>
date: Mon Aug 3 10:24:29 EDT 2015
aux/vga: dont rely on atoi() being able to parse hex
--- a/sys/src/cmd/aux/vga/db.c
+++ b/sys/src/cmd/aux/vga/db.c
@@ -146,7 +146,7 @@
Pcidev *pci;
for(t = tuple->entry; t; t = t->entry){
- if(strcmp(t->attr, "vid") != 0 || (vid=atoi(t->val)) == 0)
+ if(strcmp(t->attr, "vid") != 0 || (vid=strtol(t->val, 0, 0)) == 0)
continue;
for(td = t->line; td != t; td = td->line){
if(strcmp(td->attr, "did") != 0)
@@ -153,7 +153,7 @@
continue;
if(strcmp(td->val, "*") == 0)
did = 0;
- else if((did=atoi(td->val)) == 0)
+ else if((did=strtol(td->val, 0, 0)) == 0)
continue;
for(pci=nil; pci=pcimatch(pci, vid, did);)
if(pci->ccrb == 3)
@@ -273,7 +273,7 @@
strcpy(val, buf);
if(p = ndbgetvalue(db, &s, attr, "", "videobw", nil)){
- mode->videobw = atol(p)*1000000UL;
+ mode->videobw = strtol(p, 0, 0)*1000000UL;
free(p);
}
--- a/sys/src/cmd/aux/vga/main.c
+++ b/sys/src/cmd/aux/vga/main.c
@@ -120,7 +120,7 @@
* to set up a new one.
*/
vgactlr("addr", buf);
- if(atoi(buf)==0 && (buf[0]!='p' || buf[1]!=' ' || atoi(buf+2)==0)){
+ if(strtoul(buf, 0, 0)==0 && (buf[0]!='p' || buf[1]!=' ' || strtoul(buf+2, 0, 0)==0)){
sprint(buf, "0x%lux 0x%lux", vga->apz ? vga->apz : vga->vmz, vga->vma);
vgactlw("linear", buf);
vgactlr("addr", buf);
--- a/sys/src/cmd/aux/vga/vesa.c
+++ b/sys/src/cmd/aux/vga/vesa.c
@@ -261,7 +261,7 @@
if(vbe == nil)
error("no vesa bios\n");
- mode = atoi(dbattr(vga->mode->attr, "id"));
+ mode = strtol(dbattr(vga->mode->attr, "id"), nil, 0);
scale = dbattr(vga->mode->attr, "scale");
ds = dbattr(vga->mode->attr, "display");
display = ds == nil ? 0 : atoi(ds);