Skip to content

Commit

Permalink
Replace time_s::fmt_sprintf with time_s::fmt_str
Browse files Browse the repository at this point in the history
Because uncontrolled sprintf usage may (and did) cause problems when
compiled with _FORTIFY_SOURCE
Also it's 1.4.6 - update build files
  • Loading branch information
GregTheMadMonk committed Jan 31, 2021
1 parent 5359dea commit b21b712
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)

project(noaftodo VERSION 1.4.5)
project(noaftodo VERSION 1.4.6)

# use C++ 17
set(CXX_STANDART 17)
Expand Down
9 changes: 8 additions & 1 deletion pkg/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
2021-01-31 GregTheMadMonk <[email protected]>
* 1.4.6: Bugfix release
- Replace potentially problematic time_s::fmt_sprintf with time_s::fmt_str
- Update cmd::retval (command return value) after every command
- Update cui::status (program status line) after with every return value that is not empty
- Codebase: file naming changes, with errors causeed by it fixed

2021-01-28 GregTheMadMonk <[email protected]>
* 1.4.5r355.faca540
- Replace sprintf usage case that caused error when compiled with _FORTIFY_SOURCE

2021-01-28 GregTheMadMonk <[email protected]>
* 1.4.5r323....
* 1.4.5: TIMELINE mode release
- Added TIMELINE mode:
+ Displays tasks (surprizse) on a timeline
+ Added commands:
Expand Down
4 changes: 2 additions & 2 deletions pkg/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maintainer: Gregory Dushkin (GregTheMadMonk) <[email protected]>
pkgname=noaftodo-git
pkgver=1.4.5
pkgver=1.4.6
pkgrel=1
pkgdesc="An ncurses TODO manager that No-One-Asked-For."
arch=(x86_64 i686)
Expand All @@ -16,7 +16,7 @@ md5sums=('SKIP')

pkgver() {
cd noaftodo
printf "1.4.5r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
printf "1.4.6r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
Expand Down
23 changes: 19 additions & 4 deletions src/core/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,26 @@ struct time_s {
})

// using a custom sprintf expression
CONST_DPL(std::string fmt_sprintf(const std::string& format), {
CONST_DPL(std::string fmt_str(std::string format), {
return this->fmt([&format] (FMT_F_ARGS) {
char buffer[64];
sprintf(buffer, format.c_str(), y, M, d, h, m, s);
return std::string(buffer);
int index = -1;

while ((index = format.find("%H")) != std::string::npos)
format.replace(index, 2, std::to_string(h));

while ((index = format.find("%M")) != std::string::npos)
format.replace(index, 2, std::to_string(m));

while ((index = format.find("%d")) != std::string::npos)
format.replace(index, 2, std::to_string(d));

while ((index = format.find("%m")) != std::string::npos)
format.replace(index, 2, std::to_string(M));

while ((index = format.find("%Y")) != std::string::npos)
format.replace(index, 2, std::to_string(y));

return format;
});
})

Expand Down
4 changes: 2 additions & 2 deletions src/cui_modes/timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ void paint() {
// mark the line
const auto t = time_s("a" + to_string((position + offset) * unit));
move(h - 3, (uoffset + offset) * cpu + 1);
addnstr(t.fmt_sprintf("%1$04d/%2$02d/%3$02d").c_str(), w - (uoffset + offset) * cpu - 1);
addnstr(t.fmt_str("\%Y/%m/%d").c_str(), w - (uoffset + offset) * cpu - 1);
move(h - 2, (uoffset + offset) * cpu + 1);
addnstr(t.fmt([] (FMT_F_ARGS) { return ((h < 10) ? "0" : "") + to_string(h) + ":" + ((m < 10) ? "0" : "") + to_string(m); }).c_str(), w - (uoffset + offset) * cpu - 1);
addnstr(t.fmt_str("%H:%M").c_str(), w - (uoffset + offset) * cpu - 1);
};

const auto time_coord = [&uoffset] (const time_s& time) {
Expand Down

0 comments on commit b21b712

Please sign in to comment.