Use a custom implementation so we can use sscanf without defining _CRT_SECURE_NO_WARNINGS.

This commit is contained in:
Dirk Lemstra
2025-06-07 14:55:55 +02:00
parent 7e5d87fe6e
commit cffddd32cf
6 changed files with 31 additions and 23 deletions
-1
View File
@@ -71,7 +71,6 @@ extern "C" {
# define getpid _getpid
# define lseek _lseeki64
# define fstat _fstat64
# define sscanf sscanf_s
# define setmode _setmode
# define stat _stat64
# define tell _telli64
+3 -4
View File
@@ -55,7 +55,6 @@
#include "MagickCore/gem-private.h"
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/nt-base-private.h"
#include "MagickCore/option.h"
#include "MagickCore/paint.h"
#include "MagickCore/pixel-accessor.h"
@@ -541,7 +540,7 @@ MagickExport MagickBooleanType GradientImage(Image *image,
gradient->angle=StringToDouble(artifact,(char **) NULL);
artifact=GetImageArtifact(image,"gradient:vector");
if (artifact != (const char *) NULL)
(void) sscanf(artifact,"%lf%*[ ,]%lf%*[ ,]%lf%*[ ,]%lf",
(void) MagickSscanf(artifact,"%lf%*[ ,]%lf%*[ ,]%lf%*[ ,]%lf",
&gradient->gradient_vector.x1,&gradient->gradient_vector.y1,
&gradient->gradient_vector.x2,&gradient->gradient_vector.y2);
if ((GetImageArtifact(image,"gradient:angle") == (const char *) NULL) &&
@@ -554,7 +553,7 @@ MagickExport MagickBooleanType GradientImage(Image *image,
gradient->center.y=(double) gradient->gradient_vector.y2/2.0;
artifact=GetImageArtifact(image,"gradient:center");
if (artifact != (const char *) NULL)
(void) sscanf(artifact,"%lf%*[ ,]%lf",&gradient->center.x,
(void) MagickSscanf(artifact,"%lf%*[ ,]%lf",&gradient->center.x,
&gradient->center.y);
artifact=GetImageArtifact(image,"gradient:angle");
if ((type == LinearGradient) && (artifact != (const char *) NULL))
@@ -614,7 +613,7 @@ MagickExport MagickBooleanType GradientImage(Image *image,
}
artifact=GetImageArtifact(image,"gradient:radii");
if (artifact != (const char *) NULL)
(void) sscanf(artifact,"%lf%*[ ,]%lf",&gradient->radii.x,
(void) MagickSscanf(artifact,"%lf%*[ ,]%lf",&gradient->radii.x,
&gradient->radii.y);
gradient->radius=MagickMax(gradient->radii.x,gradient->radii.y);
gradient->spread=method;
+2 -7
View File
@@ -613,13 +613,8 @@ static void Get8BIMProperty(const Image *image,const char *key,
profile=GetImageProfile(image,"8bim");
if (profile == (StringInfo *) NULL)
return;
#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__MINGW32__)
count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%1024[^\n]\n%1024[^\n]",&start,&stop,
name,(unsigned int) sizeof(name),format,(unsigned int) sizeof(format));
#else
count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%1024[^\n]\n%1024[^\n]",&start,&stop,
name,format);
#endif
count=(ssize_t) MagickSscanf(key,"8BIM:%ld,%ld:%1024[^\n]\n%1024[^\n]",
&start,&stop,name,format);
if ((count != 2) && (count != 3) && (count != 4))
return;
if (count < 4)
+17
View File
@@ -25,6 +25,23 @@
extern "C" {
#endif
/* Custom implementation so we can use sscanf without defining _CRT_SECURE_NO_WARNINGS */
inline int MagickSscanf(const char* buffer,const char* format, ...)
{
int
ret;
va_list
args;
va_start(args,format);
#pragma warning(push)
#pragma warning(disable:4996)
ret=vsscanf(buffer,format,args);
#pragma warning(pop)
va_end(args);
return(ret);
}
static inline double SiPrefixToDoubleInterval(const char *string,
const double interval)
{
+8 -9
View File
@@ -65,7 +65,6 @@
#include "MagickCore/montage.h"
#include "MagickCore/morphology.h"
#include "MagickCore/morphology-private.h"
#include "MagickCore/nt-base-private.h"
#include "MagickCore/opencl-private.h"
#include "MagickCore/paint.h"
#include "MagickCore/pixel-accessor.h"
@@ -1122,7 +1121,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max area threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
for (i=0; i < (ssize_t) component_image->colors; i++)
if (((object[i].area < min_threshold) ||
(object[i].area >= max_threshold)) && (i != background_id))
@@ -1290,7 +1289,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max perimeter threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
metrics[++n]="perimeter";
PerimeterThreshold(component_image,object,n,exception);
for (i=0; i < (ssize_t) component_image->colors; i++)
@@ -1304,7 +1303,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max circularity threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
metrics[++n]="circularity";
CircularityThreshold(component_image,object,n,exception);
for (i=0; i < (ssize_t) component_image->colors; i++)
@@ -1318,7 +1317,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max diameter threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
metrics[++n]="diameter";
for (i=0; i < (ssize_t) component_image->colors; i++)
{
@@ -1334,7 +1333,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max ellipse major threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
metrics[++n]="major-axis";
MajorAxisThreshold(component_image,object,n,exception);
for (i=0; i < (ssize_t) component_image->colors; i++)
@@ -1348,7 +1347,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max ellipse minor threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
metrics[++n]="minor-axis";
MinorAxisThreshold(component_image,object,n,exception);
for (i=0; i < (ssize_t) component_image->colors; i++)
@@ -1362,7 +1361,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max eccentricity threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
metrics[++n]="eccentricity";
EccentricityThreshold(component_image,object,n,exception);
for (i=0; i < (ssize_t) component_image->colors; i++)
@@ -1376,7 +1375,7 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
/*
Merge any object not within the min and max ellipse angle threshold.
*/
(void) sscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
(void) MagickSscanf(artifact,"%lf%*[ -]%lf",&min_threshold,&max_threshold);
metrics[++n]="angle";
AngleThreshold(component_image,object,n,exception);
for (i=0; i < (ssize_t) component_image->colors; i++)
+1 -2
View File
@@ -45,7 +45,6 @@
#include "MagickWand/studio.h"
#include "MagickWand/MagickWand.h"
#include "MagickWand/mogrify-private.h"
#include "MagickCore/nt-base-private.h"
#include "MagickCore/string-private.h"
/*
@@ -1487,7 +1486,7 @@ WandExport MagickBooleanType MontageImageCommand(ImageInfo *image_info,
ThrowMontageInvalidArgumentException(option,argv[i]);
first_scene=StringToLong(argv[i]);
last_scene=first_scene;
(void) sscanf(argv[i],"%ld-%ld",&first_scene,&last_scene);
(void) MagickSscanf(argv[i],"%ld-%ld",&first_scene,&last_scene);
break;
}
if (LocaleCompare("seed",option+1) == 0)