ref: f629d32fa3ca1fec1e85f7e14edc3f942a1167fe
parent: 0a0395453120ef14e23e56095e09520aeb3af595
author: rodri <rgl@antares-labs.eu>
date: Mon Jun 30 10:59:24 EDT 2025
add estrdup
--- a/alloc.c
+++ b/alloc.c
@@ -33,6 +33,18 @@
return np;
}
+char *
+estrdup(char *s)
+{+ char *ns;
+
+ ns = strdup(s);
+ if(ns == nil)
+ sysfatal("strdup: %r");+ setmalloctag(ns, getcallerpc(&s));
+ return ns;
+}
+
Image*
eallocimage(Display *d, Rectangle r, ulong chan, int repl, ulong col)
{--- a/fns.h
+++ b/fns.h
@@ -1,5 +1,6 @@
void *emalloc(ulong);
void *erealloc(void*, ulong);
+char *estrdup(char*);
Image *eallocimage(Display*, Rectangle, ulong, int, ulong);
Memimage *eallocmemimage(Rectangle, ulong);
void qball(Rectangle, Point, Point, Quaternion*, Quaternion*);
--- a/med.c
+++ b/med.c
@@ -503,8 +503,10 @@
t0 = nanosec();
}else{Δt = HZ2NS(60) - Δt;
- if(Δt >= 1000000ULL)
+ if(Δt > 1000000ULL)
sleep(Δt/1000000ULL);
+ else
+ sleep(1);
}
}
}
--- a/obj.c
+++ b/obj.c
@@ -158,10 +158,7 @@
mtl = &m->materials[m->nmaterials-1];
memset(mtl, 0, sizeof *mtl);
- mtl->name = strdup(objmtl->name);
- if(mtl->name == nil)
- sysfatal("strdup: %r");-
+ mtl->name = estrdup(objmtl->name);
if(objmtl->Ka.a > 0)
mtl->ambient = objmtl->Ka;
if(objmtl->Kd.a > 0)
--- a/solar.c
+++ b/solar.c
@@ -237,9 +237,7 @@
break;
case RADIUS: snprint(buf, sizeof buf, "radius (in km): %g", p->scale*↓scale); break;
}
- items[i] = strdup(buf);
- if(items[i] == nil)
- sysfatal("strdup: %r");+ items[i] = estrdup(buf);
}
items[i] = nil;
@@ -421,7 +419,7 @@
lastline = line;
}
if(lastline != nil)
- lastline = strdup(lastline);
+ lastline = estrdup(lastline);
Bterm(bin);
close(r.pfd[0]);
}
@@ -586,8 +584,10 @@
t0 = nanosec();
}else{Δt = HZ2NS(60) - Δt;
- if(Δt >= 1000000ULL)
+ if(Δt > 1000000ULL)
sleep(Δt/1000000ULL);
+ else
+ sleep(1);
}
}
}
--- a/toobj.c
+++ b/toobj.c
@@ -62,7 +62,7 @@
objmtl->map_Kd = emalloc(sizeof(OBJTexture));
objmtl->map_Kd->image = dupmemimage(mtl->diffusemap->image);
objmtl->map_Kd->filename = mtl->diffusemap->file != nil?
- strdup(mtl->diffusemap->file):
+ estrdup(mtl->diffusemap->file):
smprint("%s_diffuse.png", mtl->name);}
@@ -70,7 +70,7 @@
objmtl->map_Ks = emalloc(sizeof(OBJTexture));
objmtl->map_Ks->image = dupmemimage(mtl->specularmap->image);
objmtl->map_Ks->filename = mtl->specularmap->file != nil?
- strdup(mtl->specularmap->file):
+ estrdup(mtl->specularmap->file):
smprint("%s_specular.png", mtl->name);}
@@ -78,7 +78,7 @@
objmtl->norm = emalloc(sizeof(OBJTexture));
objmtl->norm->image = dupmemimage(mtl->normalmap->image);
objmtl->norm->filename = mtl->normalmap->file != nil?
- strdup(mtl->normalmap->file):
+ estrdup(mtl->normalmap->file):
smprint("%s_normal.png", mtl->name);}
--- a/vis.c
+++ b/vis.c
@@ -316,8 +316,10 @@
t0 = nanosec();
}else if(!doprof){Δt = HZ2NS(60) - Δt;
- if(Δt >= 1000000ULL)
+ if(Δt > 1000000ULL)
sleep(Δt/1000000ULL);
+ else
+ sleep(1);
}
}
}
--
⑨