(PSDRV_AFMGetCharMetrics): Use unsigned chars (since isspace is used).

(PSDRV_AFMParse): Don't crash on missing font name.  Use unsigned
chars.  Fix peculiar inconsistent indentation.  Don't leak a FILE.
Catch problematic files with no line feed in them.  Don't mix
characters and integers.  Don't overrun the buffer.
This commit is contained in:
Morten Welinder 2001-02-15 21:23:50 +00:00 committed by Alexandre Julliard
parent ed6a7b4ab2
commit ae70f5c647

View file

@ -34,8 +34,8 @@ FONTFAMILY *PSDRV_AFMFontList = NULL;
*/ */
static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp) static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp)
{ {
char line[256], valbuf[256]; unsigned char line[256], valbuf[256];
char *cp, *item, *value, *curpos, *endpos; unsigned char *cp, *item, *value, *curpos, *endpos;
int i; int i;
AFMMETRICS *metric; AFMMETRICS *metric;
@ -63,7 +63,7 @@ static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp)
while(isspace(*value)) while(isspace(*value))
value++; value++;
cp = endpos = strchr(value, ';'); cp = endpos = strchr(value, ';');
if (!cp) { ERR("missing ;, failed.\n"); return; } if (!cp) { ERR("missing ;, failed. [%s]\n", line); return; }
while(isspace(*--cp)) while(isspace(*--cp))
; ;
memcpy(valbuf, value, cp - value + 1); memcpy(valbuf, value, cp - value + 1);
@ -126,11 +126,12 @@ static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp)
static AFM *PSDRV_AFMParse(char const *file) static AFM *PSDRV_AFMParse(char const *file)
{ {
FILE *fp; FILE *fp;
char buf[256]; unsigned char buf[256];
char *value; unsigned char *value;
AFM *afm; AFM *afm;
char *cp; unsigned char *cp;
int afmfile = 0; int afmfile = 0;
int c;
TRACE("parsing '%s'\n", file); TRACE("parsing '%s'\n", file);
@ -146,31 +147,29 @@ static AFM *PSDRV_AFMParse(char const *file)
} }
cp = buf; cp = buf;
while ( ( *cp = fgetc ( fp ) ) != EOF ) { while ( ( c = fgetc ( fp ) ) != EOF ) {
if ( *cp == '\r' || *cp == '\n' || cp - buf == sizeof(buf)-1 ) { *cp = c;
if ( cp == buf ) if ( *cp == '\r' || *cp == '\n' || cp - buf == sizeof(buf)-2 ) {
continue; if ( cp == buf )
*(cp+1)='\0'; continue;
} *(cp+1)='\0';
else {
cp ++;
continue;
}
cp = buf + strlen(buf);
do {
*cp = '\0';
cp--;
} while(cp > buf && isspace(*cp));
cp = buf;
if ( afmfile == 0 && strncmp ( buf, "StartFontMetrics", 16 ) ) {
HeapFree ( PSDRV_Heap, 0, afm );
return NULL;
} }
else { else {
afmfile = 1; cp ++;
continue;
} }
cp = buf + strlen(buf);
do {
*cp = '\0';
cp--;
} while(cp > buf && isspace(*cp));
cp = buf;
if ( afmfile == 0 && strncmp ( buf, "StartFontMetrics", 16 ) )
break;
afmfile = 1;
value = strchr(buf, ' '); value = strchr(buf, ' ');
if(value) if(value)
@ -276,8 +275,15 @@ static AFM *PSDRV_AFMParse(char const *file)
} }
fclose(fp); fclose(fp);
if(afm->FontName == NULL) if (afmfile == 0) {
HeapFree ( PSDRV_Heap, 0, afm );
return NULL;
}
if(afm->FontName == NULL) {
WARN("%s contains no FontName.\n", file); WARN("%s contains no FontName.\n", file);
afm->FontName = HEAP_strdupA(PSDRV_Heap, 0, "nofont");
}
if(afm->FullName == NULL) if(afm->FullName == NULL)
afm->FullName = HEAP_strdupA(PSDRV_Heap, 0, afm->FontName); afm->FullName = HEAP_strdupA(PSDRV_Heap, 0, afm->FontName);
if(afm->FamilyName == NULL) if(afm->FamilyName == NULL)