Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8a6d6e5b
Commit
8a6d6e5b
authored
Dec 18, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delta_str(): Purged last uses of sprintf (in favor of PyOS_snprintf).
parent
fc1e4ec9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
10 deletions
+25
-10
Modules/datetimemodule.c
Modules/datetimemodule.c
+25
-10
No files found.
Modules/datetimemodule.c
View file @
8a6d6e5b
...
...
@@ -1805,27 +1805,42 @@ delta_str(PyDateTime_Delta *self)
int
us
=
GET_TD_MICROSECONDS
(
self
);
int
hours
;
int
minutes
;
char
buf
[
500
];
int
i
=
0
;
char
buf
[
100
];
char
*
pbuf
=
buf
;
size_t
buflen
=
sizeof
(
buf
);
int
n
;
minutes
=
divmod
(
seconds
,
60
,
&
seconds
);
hours
=
divmod
(
minutes
,
60
,
&
minutes
);
if
(
days
)
{
i
+=
sprintf
(
buf
+
i
,
"%d day%s, "
,
days
,
(
days
==
1
||
days
==
-
1
)
?
""
:
"s"
);
assert
(
i
<
sizeof
(
buf
));
n
=
PyOS_snprintf
(
pbuf
,
buflen
,
"%d day%s, "
,
days
,
(
days
==
1
||
days
==
-
1
)
?
""
:
"s"
);
if
(
n
<
0
||
(
size_t
)
n
>=
buflen
)
goto
Fail
;
pbuf
+=
n
;
buflen
-=
(
size_t
)
n
;
}
i
+=
sprintf
(
buf
+
i
,
"%d:%02d:%02d"
,
hours
,
minutes
,
seconds
);
assert
(
i
<
sizeof
(
buf
));
n
=
PyOS_snprintf
(
pbuf
,
buflen
,
"%d:%02d:%02d"
,
hours
,
minutes
,
seconds
);
if
(
n
<
0
||
(
size_t
)
n
>=
buflen
)
goto
Fail
;
pbuf
+=
n
;
buflen
-=
(
size_t
)
n
;
if
(
us
)
{
i
+=
sprintf
(
buf
+
i
,
".%06d"
,
us
);
assert
(
i
<
sizeof
(
buf
));
n
=
PyOS_snprintf
(
pbuf
,
buflen
,
".%06d"
,
us
);
if
(
n
<
0
||
(
size_t
)
n
>=
buflen
)
goto
Fail
;
pbuf
+=
n
;
}
return
PyString_FromStringAndSize
(
buf
,
i
);
return
PyString_FromStringAndSize
(
buf
,
pbuf
-
buf
);
Fail:
PyErr_SetString
(
PyExc_SystemError
,
"goofy result from PyOS_snprintf"
);
return
NULL
;
}
/* Pickle support. Quite a maze! While __getstate__/__setstate__ sufficed
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment