[Mplayer-cvslog] CVS: main cpudetect.c,1.8,1.9 cpudetect.h,1.4,1.5

pl pl at mplayer.dev.hu
Sat Oct 20 13:16:51 CEST 2001


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv28778

Modified Files:
	cpudetect.c cpudetect.h 
Log Message:
returns a malloc()'ed string instead of an auto char[]


Index: cpudetect.c
===================================================================
RCS file: /cvsroot/mplayer/main/cpudetect.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- cpudetect.c	20 Oct 2001 02:35:31 -0000	1.8
+++ cpudetect.c	20 Oct 2001 11:16:47 -0000	1.9
@@ -93,9 +93,13 @@
 	printf("CPU vendor name: %.4s%.4s%.4s  max cpuid level: %d\n",&regs[1],&regs[3],&regs[2],regs[0]);
 	if (regs[0]>=0x00000001)
 	{
+		char *tmpstr;
+		
 		do_cpuid(0x00000001, regs2);
 
-		printf("CPU: %s\n",GetCpuFriendlyName(regs, regs2));
+		tmpstr=GetCpuFriendlyName(regs, regs2);
+		printf("CPU: %s\n",tmpstr);
+		free(tmpstr);
 
 		caps->cpuType=(regs2[0] >> 8)&0xf;
 		if(caps->cpuType==0xf){
@@ -153,17 +157,22 @@
 char *GetCpuFriendlyName(unsigned int regs[], unsigned int regs2[]){
 #include "cputable.h" /* get cpuname and cpuvendors */
 	char vendor[17];
-	char retname[255];
+	char *retname;
 	int i;
 
+	if (NULL==(retname=malloc(256))) {
+		printf("Error: GetCpuFriendlyName() not enough memory\n");
+		exit(1);
+	}
+
 	sprintf(vendor,"%.4s%.4s%.4s",&regs[1],&regs[3],&regs[2]);
 	
 	for(i=0; i<MAX_VENDORS; i++){
 		if(!strcmp(cpuvendors[i].string,vendor)){
 			if(cpuname[i][CPUID_FAMILY][CPUID_MODEL]){
-				sprintf(retname,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]);
+				snprintf(retname,255,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]);
 			} else {
-				sprintf(retname,"unknown %s %d. Generation CPU",cpuvendors[i].name,CPUID_FAMILY); 
+				snprintf(retname,255,"unknown %s %d. Generation CPU",cpuvendors[i].name,CPUID_FAMILY); 
 				printf("unknown %s CPU:\n",cpuvendors[i].name);
 				printf("Vendor:   %s\n",cpuvendors[i].string);
 				printf("Type:     %d\n",CPUID_TYPE);

Index: cpudetect.h
===================================================================
RCS file: /cvsroot/mplayer/main/cpudetect.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- cpudetect.h	20 Oct 2001 02:35:31 -0000	1.4
+++ cpudetect.h	20 Oct 2001 11:16:47 -0000	1.5
@@ -18,6 +18,8 @@
 extern CpuCaps gCpuCaps;
 
 void GetCpuCaps(CpuCaps *caps);
+
+/* returned value is malloc()'ed so free() it after use */
 char *GetCpuFriendlyName(unsigned int regs[], unsigned int regs2[]);
 
 #endif /* ARCH_X86 */




More information about the MPlayer-cvslog mailing list