Skip to content

Commit

Permalink
Fix #1637 - off-by-one error in printfile_random causes it to display…
Browse files Browse the repository at this point in the history
… nothing sometimes
  • Loading branch information
ericpareja committed Dec 3, 2024
1 parent b14dcfa commit 38aea8a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion common/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "common/context.h"
#include "common/remote_io.h"
#include <chrono>
#include <cstdint>
#include <functional>
#include <set>
#include <string>
Expand Down
5 changes: 3 additions & 2 deletions common/printfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ void Output::print_local_file(const std::string& data) {

bool Output::printfile_random(const std::string& data) {
const printfile_opts opts(sess(), *this, data, true, true);
const auto& dir = sess().dirs().current_menu_gfiles_directory();
// const auto& dir = sess().dirs().current_menu_gfiles_directory();
const auto& dir = sess().dirs().gfiles_directory();
const auto base_fn = opts.data();
if (const auto dot_zero = FilePath(dir, StrCat(base_fn, ".0")); !File::Exists(dot_zero)) {
return false;
Expand All @@ -269,7 +270,7 @@ bool Output::printfile_random(const std::string& data) {
break;
}
}
return printfile_path(FilePath(dir, StrCat(base_fn, ".", os::random_number(screens))),
return printfile_path(FilePath(dir, StrCat(base_fn, ".", os::random_number(screens-1))),
opts.abortable, opts.force_pause);
}

Expand Down
1 change: 0 additions & 1 deletion sdk/ansi/makeansi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/**************************************************************************/
#include "sdk/ansi/makeansi.h"

#include <cstdint>
#include <string>
#include <vector>

Expand Down
14 changes: 9 additions & 5 deletions sdk/ansi/makeansi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
/* either express or implied. See the License for the specific */
/* language governing permissions and limitations under the License. */
/**************************************************************************/
#ifndef INCLUDED_SDK_MAKEANSI_H
#define INCLUDED_SDK_MAKEANSI_H
#ifndef __INCLUDED_SDK_MAKEANSI_H__
#define __INCLUDED_SDK_MAKEANSI_H__

#include <string>

namespace wwiv::sdk::ansi {
namespace wwiv {
namespace sdk {
namespace ansi {

/**
* Passed to this function is a one-byte attribute as defined for IBM type
Expand All @@ -29,6 +31,8 @@ namespace wwiv::sdk::ansi {
*/
std::string makeansi(int attr, int current_attr);

} // namespace wwiv::sdk::ansi
} // namespace ansi
} // namespace sdk
} // namespace wwiv

#endif // INCLUDED_SDK_MAKEANSI_H
#endif // __INCLUDED_SDK_MAKEANSI_H__

0 comments on commit 38aea8a

Please sign in to comment.